Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 249
ngDeveloper Avatar asked Sep 10 '15 21:09

ngDeveloper


People also ask

Why npm install not working?

The Npm command not found error can appear when you install or upgrade npm. On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.

How do I force an npm package to install?

Run npm update -g npm. Execute this command by running the command prompt as Administrator npm install -g windows-build-tools. Run npm install inside the project folder where the package. json file is located, if it doesn't work run: npm install --force.

Does npm install globally by default?

In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package. By default, npm install will install all modules listed as dependencies in package.


2 Answers

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.

like image 119
ngDeveloper Avatar answered Oct 12 '22 05:10

ngDeveloper


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.

like image 1
Brijesh Ray Avatar answered Oct 12 '22 04:10

Brijesh Ray