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 16:05

get the path from npm:

npm config get prefix

and just as a future reference, this is the path I added in Windows 10:

C:\Users\{yourName}\AppData\Roaming\npm

查看更多
伤终究还是伤i
3楼-- · 2019-01-02 16:07

You need to Add C:\Program Files\nodejs to your PATH environment variable. To do this follow these steps:

  1. Use the global Search Charm to search "Environment Variables"
  2. Click "Edit system environment variables"
  3. Click "Environment Variables" in the dialog.
  4. In the "System Variables" box, search for Path and edit it to include C:\Program Files\nodejs. Make sure it is separated from any other paths by a ;.

You will have to restart any currently-opened command prompts before it will take effect.

查看更多
像晚风撩人
4楼-- · 2019-01-02 16:13

Try this one dude if you're using windows:

1.) Search environment variables at your start menu's search box.
2.) Click it then go to Environment Variables...
3.) Click PATH, click Edit
4.) Click New and try to copy and paste this: C:\Program Files\nodejs\node_modules\npm\bin

If you got an error. Do the number 4.) Click New, then browse the bin folder

  • You may also Visit this link for more info.
查看更多
登录 后发表回答