7

解决npm全局安装任何工具都提示“不是内部或外部命令”的问题

 1 year ago
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.
neoserver,ios ssh client

解决npm全局安装任何工具都提示“不是内部或外部命令”的问题

使用npm安装cnpm、pnpm、yarn后发现使用不了,而安装过程没报任何错误,尝试清理npm缓存等操作都无法解决



  1. PS C:\Users\User> npm install -g cnpm
  2. added 361 packages, and audited 572 packages in 21s
  3. 27 packages are looking for funding
  4. run `npm fund` for details
  5. found 0 vulnerabilities
  6. PS C:\Users\User> cnpm -v
  7. cnpm : 无法将“cnpm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。

最后使用npm config list查看npm配置发现了端倪,不知道为啥配置了bin-links = false,关闭这个配置将会导致安装带有可执行程序的工具时不会将可执行程序链接到npm全局目录下。



  1. PS C:\Users\User> npm config list
  2. ; "builtin" config from D:\Program Files\nodejs\node_modules\npm\npmrc
  3. prefix = "C:\\Users\\User\\AppData\\Roaming\\npm"
  4. ; "user" config from C:\Users\User\.npmrc
  5. bin-links = false
  6. ; node bin location = D:\Program Files\nodejs\node.exe
  7. ; node version = v16.17.0
  8. ; npm local prefix = C:\Users\User
  9. ; npm version = 8.15.0
  10. ; cwd = C:\Users\User
  11. ; HOME = C:\Users\User
  12. ; Run `npm config ls -l` to show all defaults.

重新开启配置



  1. npm config set bin-links true

重新安装cnpm、pnpm、yarn然后就O了



  1. PS C:\Users\User> npm install -g cnpm
  2. changed 376 packages, and audited 572 packages in 24s
  3. 27 packages are looking for funding
  4. run `npm fund` for details
  5. found 0 vulnerabilities
  6. PS C:\Users\User> cnpm -v
  7. [email protected] (C:\Users\User\AppData\Roaming\npm\node_modules\cnpm\lib\parse_argv.js)
  8. [email protected] (C:\Users\User\AppData\Roaming\npm\node_modules\cnpm\node_modules\npm\index.js)
  9. [email protected] (D:\Program Files\nodejs\node.exe)
  10. [email protected] (C:\Users\User\AppData\Roaming\npm\node_modules\cnpm\node_modules\npminstall\lib\index.js)
  11. prefix=C:\Users\User\AppData\Roaming\npm
  12. win32 x64 10.0.19044
  13. registry=https://registry.npmmirror.com

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK