npm command fails with 'CALL node.exe npm-prefix.js is not recognized' error on Windows

I’m having trouble with npm on my Windows machine. When I try to run npm -v, I get this weird error message that says ‘CALL “C:\Program Files\nodejs\node.exe” “C:\Program Files\nodejs\node_modules\npm\bin\npm-prefix.js”’ is not recognized as an internal or external command.

The strange thing is that Node.js itself works perfectly fine. When I run node -v, it shows the version without any problems. But whenever I try to use npm commands, they just don’t work and throw these ENOENT spawn errors.

I’ve tried restarting my computer and checking my PATH environment variables, but nothing seems to help. Has anyone encountered this issue before? I’m wondering if I need to completely uninstall Node.js and npm and then reinstall everything from scratch.

What would be the best way to fix this npm issue or do a clean reinstall on Windows?

This issue arises when the installation path of Node.js contains spaces or special characters, causing conflicts in the Windows command prompt. It’s not inherently a Node.js error, but rather pertains to how npm batch files execute. I experienced this problem first-hand after installing Node.js in the Program Files directory. The solution was to completely uninstall Node.js and then reinstall it in a directory without spaces, such as C:\nodejs. Once I updated my PATH environment variable to reflect the new installation path, the npm-prefix.js error disappeared and npm functioned correctly.

had this same issue b4! turned out my npm cache was really messed up. try running npm cache clean --force in cmd as admin. that did the trick for me. if it still fails, just delete the npm folder in your nodejs dir and reinstall npm fresh.

I faced a similar issue recently. It’s often caused by a corrupted npm installation while Node.js remains functional. To resolve it, I downloaded the latest Node.js installer and opted for the repair feature, which restored npm without affecting my Node.js setup. If the repair option does not resolve the issue, consider executing npm-prefix.js manually from your Node.js directory. This action may reveal specific problems such as permission issues or a corrupted cache.