7
解决npm全局安装任何工具都提示“不是内部或外部命令”的问题
source link: https://www.liesauer.net/blog/post/fix-npm-install-tools-with--g-is-not-recognized-as-an-internal-or-external-command-error.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
解决npm全局安装任何工具都提示“不是内部或外部命令”的问题
使用npm安装cnpm、pnpm、yarn后发现使用不了,而安装过程没报任何错误,尝试清理npm缓存等操作都无法解决
PS C:\Users\User> npm install -g cnpm
added 361 packages, and audited 572 packages in 21s
27 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
PS C:\Users\User> cnpm -v
cnpm : 无法将“cnpm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
最后使用npm config list
查看npm配置发现了端倪,不知道为啥配置了bin-links = false
,关闭这个配置将会导致安装带有可执行程序的工具时不会将可执行程序链接到npm全局目录下。
PS C:\Users\User> npm config list
; "builtin" config from D:\Program Files\nodejs\node_modules\npm\npmrc
prefix = "C:\\Users\\User\\AppData\\Roaming\\npm"
; "user" config from C:\Users\User\.npmrc
bin-links = false
; node bin location = D:\Program Files\nodejs\node.exe
; node version = v16.17.0
; npm local prefix = C:\Users\User
; npm version = 8.15.0
; cwd = C:\Users\User
; HOME = C:\Users\User
; Run `npm config ls -l` to show all defaults.
重新开启配置
npm config set bin-links true
重新安装cnpm、pnpm、yarn然后就O了
PS C:\Users\User> npm install -g cnpm
changed 376 packages, and audited 572 packages in 24s
27 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
PS C:\Users\User> cnpm -v
[email protected] (C:\Users\User\AppData\Roaming\npm\node_modules\cnpm\lib\parse_argv.js)
[email protected] (C:\Users\User\AppData\Roaming\npm\node_modules\cnpm\node_modules\npm\index.js)
[email protected] (D:\Program Files\nodejs\node.exe)
[email protected] (C:\Users\User\AppData\Roaming\npm\node_modules\cnpm\node_modules\npminstall\lib\index.js)
prefix=C:\Users\User\AppData\Roaming\npm
win32 x64 10.0.19044
registry=https://registry.npmmirror.com
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK