控制台 安装 Vue-Cli 最后一步出现 Error: Cannot find module 'node:util' 问题解决方案
1.问题
C:\Windows\System32>cnpm install -g @vue/cli@4.0.3
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'node:util'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (C:\Users\DELL\AppData\Roaming\npm\node_modules\cnpm\bin\cnpm:3:15)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2.解决方案
npm 与 cnpm 版本不匹配,需要匹配新的cnpm(记得先删除之前的)
npm uninstall cnpm
当前npm版本
C:\Windows\System32>npm -v 6.9.0
安装cnpm指定版本
C:\Windows\System32>npm install -g cnpm@7.1.1 --registry=https://registry.npm.taobao.org
npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details. npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 npm WARN deprecated har-validator@5.1.5: this library is no longer supported npm WARN deprecated @npmcli/move-file@1.1.2: This functionality has been moved to @npmcli/fs C:\Users\DELL\AppData\Roaming\npm\cnpm -> C:\Users\DELL\AppData\Roaming\npm\node_modules\cnpm\bin\cnpm npm WARN urllib@2.41.0 requires a peer of proxy-agent@^5.0.0 but none is installed. You must install peer dependencies yourself. + cnpm@7.1.1 added 418 packages from 137 contributors, removed 278 packages, updated 215 packages and moved 10 packages in 45.271s
npm install webpack@4.41.2 webpack-cli -D
安装 vue-cli cnpm install -g @vue/cli@4.0.3
cnpm install -g @vue/cli@4.0.3
C:\Windows\System32>cnpm -v cnpm@7.1.1 (C:\Users\DELL\AppData\Roaming\npm\node_modules\cnpm\lib\parse_argv.js) npm@6.14.18 (C:\Users\DELL\AppData\Roaming\npm\node_modules\cnpm\node_modules\npm\lib\npm.js) node@10.16.3 (D:\Program Files (x86)\nodejs10.16\node.exe) npminstall@5.8.1 (C:\Users\DELL\AppData\Roaming\npm\node_modules\cnpm\node_modules\npminstall\lib\index.js) prefix=C:\Users\DELL\AppData\Roaming\npm win32 x64 10.0.22621 registry=https://registry.npmmirror.com