mac 安装cnpm报错internal/modules/cjs/loader.js:905 throw err; ^ Error: Cannot find module 'node:util'
错误复现:
安装cnpm
npm install -g cnpm
运行cnpm
cnpm
报错如下
internal/modules/cjs/loader.js:905
throw err;
^
Error: Cannot find module 'node:util'
Require stack:
- /Users/xxx/.nvm/versions/node/v14.17.3/lib/node_modules/cnpm/bin/cnpm
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/Users/xxx/.nvm/versions/node/v14.17.3/lib/node_modules/cnpm/bin/cnpm:3:15)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/xxx/.nvm/versions/node/v14.17.3/lib/node_modules/cnpm/bin/cnpm'
]
}
解决方式
降低cnpm版本
1.先卸载cnpm
npm uninstall cnpm
2.通过上边的报错能知道当前cnpm是安装到了这里
/Users/xxx/.nvm/versions/node/v14.17.3/lib/node_modules
然后可以运行命令打开这个文件夹
open /Users/xxx/.nvm/versions/node/v14.17.3/lib/node_modules
此时能看到cnpm文件夹,把这个文件夹删掉
3.然后重新安装一个低版本的文章来源:https://www.toymoban.com/news/detail-623400.html
npm install cnpm@6.0.0
再次执行cnpm 即可生效文章来源地址https://www.toymoban.com/news/detail-623400.html
到了这里,关于mac 安装cnpm报错internal/modules/cjs/loader.js:905的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!