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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With