'Global NPM package installed but command not found
I have globally installed two npm packages "download" and "enigmavirtualbox" via command line:
npm install -g download and
npm install -g engimavirtualbox
I'm trying to use them in a batch file to bundle a single .exe file from my node project. For both, the commands npm list -g <packagename> yield the respective version output, independent of the present working directory.
However, inside my batch script the commands "download" and "enigmavirtualbox" cannot be found.
Running npm root -g yields C:\Users\<username>\AppData\Roaming\npm\node_modules and looking inside that folder I can see that folders for both packages are present.
What I have tried:
- Changing
npm rootas described here - Uninstall and reinstall packages
- Add env. variable NODE_PATH to point to
C:\Users\<username>\AppData\Roaming\npm\node_modules - Add
C:\Users\<username>\AppData\Roaming\npm\node_modulesto PATH env. variable
The same setup works on my second computer (both run Win7 64bit). Is something wrong with my node installation, or what am I doing wrong?
Solution 1:[1]
If the above method does not work then use this command to explicitly set the path
npm config set prefix c:/Users/<username>/AppData/Roaming/npm
Solution 2:[2]
Short answer: Add %APPDATA%\npm to the PATH environment variable.
Long answer:
npm saves the .cmd file which gets executed when you execute a command from a npm package (and everything is working as it should) in the C:\Users\%username%\AppData\Roaming\npm directory (%username% is the username of the current user).
Because userprofiles are not necessarily inside of C:\Users it's better to use a variable like %userprofile% which points to the userprofile of the current user or %APPDATA% which points to AppData\Roaming inside of the userprofile of the current user.
By adding %APPDATA%\npm to the PATH env. variable windows automatically searches there for a file with the name you entered as a command if the current directory doesn't contain a file with that name.
For every command there is also a file without a suffix in the npm folder which is a bash script and wont work on Windows (if you don't use bash) but Windows finds the .cmd file first so you don't have to worry about that.
Solution 3:[3]
Here more info about this topic : https://medium.com/@alberto.schiabel/npm-tricks-part-1-get-list-of-globally-installed-packages-39a240347ef0
List of packages which have been install globally
npm list -g --depth 0
Solution 4:[4]
Set your PATH environment variable to C:\Users\YOUR_USERNAME\AppData\Roaming\npm. This fixed it for me.
Solution 5:[5]
Just run this command
SET PATH=%AppData%\npm;%PATH%
Solution 6:[6]
For anyone who's still having issues with missing commands. I have been dealing with this for a couple weeks and all but abandoned hope developing on windows. Then ran npm config list and found this:
; userconfig C:\Users\deane\.npmrc
bin-links = false
Need to change that to true. Even uninstalling and reinstalling doesn't help because it retains your .npmrc file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mr.Noob |
| Solution 2 | |
| Solution 3 | zloctb |
| Solution 4 | Joshua Verdehem |
| Solution 5 | testing_22 |
| Solution 6 | Deane |
