Fixing npm path in Windows 8 and 10

2019-01-02 15:33发布

Have done a lot of googling, tried reinstalling node.js using the official installer, but my npm pathing still doesn't work.

This doesn't work

npm install foo

I get an error message saying missing module npm-cli.js

2 hours of googling later I discovered a workaround
Instead of simply 'npm' I type

node C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js

But how can I correct my nodejs install so I can simply type 'npm' ?

标签: node.js npm
9条回答
看淡一切
2楼-- · 2019-01-02 15:48

I've had this issue in 2 computers in my house using Windows 10 each. The problem began when i had to change few Environmental variables for projects that I've been working on Visual studio 2017 etc. After few months coming back to using node js and npm I had this issue again and non of the solutions above helped. I saw Sean's comment on Yar's solution and i mixed both solutions: 1) at the environmental variables window i had one extra variable that held this value: %APPDATA%\npm. I deleted it and the problem dissapeared!

查看更多
余生无你
3楼-- · 2019-01-02 15:54

I have used the cmdlet and navigate to the path you want to switch your npm files to. Type in npm root -g to see what the current path your npm is installed to. Next use npm config set prefix and your npm path will be changed to whatever directory you are currently on.

查看更多
谁念西风独自凉
4楼-- · 2019-01-02 15:56

Go to control panel -> System -> Advanced System Settings then environment variables.

From here find the path variable, Go to the end of the line and paste "C:\Program Files\nodejs\node_modules\npm\bin" (change the path to the directory to where ever you installed it e.g. if you specifically installed it anywhere change it)

查看更多
余生无你
5楼-- · 2019-01-02 15:56

Installed Node Version Manager (NVM) for Windows: https://github.com/coreybutler/nvm-windows

I'm using Windows 10 - 64 bit so I run... Commands:

  • nvm arch 64 (to make default the 64 bit executable)
  • nvm list (to list all available node versions)
  • nvm install 8.0.0 (to download node version 8.0.0 - you can pick any)
  • nvm use 8.0.0 (to use that specific version)

In my case I had to just switch to version 8.5.0 and then switch back again to 8.0.0 and it was fixed. Apparently NVM sets the PATH variables whenever you do that switch.

查看更多
谁念西风独自凉
6楼-- · 2019-01-02 15:57

This worked for me: 1. npm root -g (to see the current npm is installed) 2. npm config set prefix (to change the path)

查看更多
残风、尘缘若梦
7楼-- · 2019-01-02 16:02

change the path for nodejs in environment varibale.

setting environment variable

查看更多
登录 后发表回答