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?
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.