Cannot get “npm install -g” to work on any packages (AppData/Roaming/npm always empty)

喜欢而已 提交于 2020-12-05 11:33:09

问题


Running nodejs on Windows 7 Enterprise at work.

Whenever I install a node_module that needs -g access, from experience I know it's supposed to create a *.bat file in %AppData$/Roaming/npm, but for some reason it no longer does that.

For example, I will run npm install gulp -g, console looks like it installed correctly, but the files will not be in the AppData folder. And if I try running a gulp command, I get error sh.exe": gulp: command not found.

If I run the npm install gulp -g command in Console As Administrator, it installs the files into the %AppData% folder of the administrator (instead of the regular user). So if I run the gulp command through my non-administrator user, I still get error sh.exe": gulp: command not found.

Any ideas?


回答1:


Found solution:

(1) Upon running the command: npm config get prefix, output is C:\Program Files (x86)\Git\local. No idea why it was set to this, as it's not the default.

But I changed it using: npm config set prefix "$APPDATA\npm".

Now when I install a --g module, ie. npm install gulp -g, it installs into this desirable directory, no longer throwing EPERM and ENOENT errors.

(2) Still need to add a PATH entry for the npm folder. The command export PATH=$PATH:/c/Users/{YOUR_USERNAME}/AppData/Roaming/npm works temporarily, but if you close console and open it again, might not be saved (if you are not an administrator).

But you can also use echo 'export PATH=$PATH:/c/Users/{YOUR_USERNAME}/AppData/Roaming/npm' >> ~/.bash_profile, which will create a .bash_profile file, which is run each time as your console is opened. So from this point, it should automatically add the required PATH entry.



来源:https://stackoverflow.com/questions/32512154/cannot-get-npm-install-g-to-work-on-any-packages-appdata-roaming-npm-always

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!