Cannot get "npm install -g" to work on any packages (AppData/Roaming/npm always empty)
Asked Answered
C

2

6

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?

Coffeng answered 10/9, 2015 at 21:46 Comment(0)
C
15

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.

Coffeng answered 11/9, 2015 at 0:26 Comment(5)
Spent hours looking for a solution that would work. Thanks!Howund
I wasted hours on this too. Pppppppppppppp. Software development, amaright?Coffeng
For exporting the path you may also edit the system environment variable; path = %appdata%/npm;Molnar
Like Div Tiwari said, edit your system environment variables and then close your command line and reopen it. It will working.Adularia
Thanks a lot for the solution. In my case a folder $Appdata/npm/ was getting created which was leading to the confusion.Drislane
E
3

I also faced this same issue.

After installing node.js(https://nodejs.org/en/download/) npm folder(in appdata folder) remain empty.

so, at this stage if you try to build/run angular project(ng build/ng serve), it will give error as:

The term 'ng' is not recognized as the name of a cmdlet, function, script file, or operable program. 

So, for fixing this issue install angular globally in your project with following command:

npm install -g @angular/cli

Now, there would be data in npm folder(node modules etc.) and ng command will run now.

Erethism answered 31/3, 2022 at 16:28 Comment(2)
After hours of searching this was the only answer which managed to help me out.Orwin
I too spent the last 3 hours fiddling with environment variables, uninstalling and reinstalling node, and everything else. Nothing worked. This quickly did. Thanks.Foray

© 2022 - 2024 — McMap. All rights reserved.