npm.cmd
says "The system cannot find the file specified. (os error 2)" on every command.
For example
>npm -v
Error:
x The system cannot find the file specified. (os error 2)
8.11.0
The command works fine seemingly, but the process return code is nonzero, which causes many npm scripts to fail.
I've installed several node versions (with nvm for windows) on two different laptops (win 10 and win 11), but they all have the same problem. Googling this yields nothing to my surprise.
Another interesting observation is that the bash script called npm
(located beside npm.cmd
in the installation directory) does not have this problem when running it in git bash. However, some programs and scripts depending on npm will use the npm.cmd regardless of how I call them apparently, so the issue still persists for me. I've tried running npm config set script-shell bash
to workaround this, but it does not seem to work.
I had a custom shell configured in the ComSpec
environment variable. Removing this fixed the problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.