Global NPM package installed but command not found
Windowsnode.jsBatch FileNpmPackageWindows Problem Overview
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 root
as 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_modules
to 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?
Windows Solutions
Solution 1 - Windows
The executable binaries and .cmd files end up in C:\Users\<username>\AppData\Roaming\npm
(minus the node_modules
at the end) so adding that path to the PATH env. variable fixed the issue.
With environment variables, the path can be abbreviated: %appdata\npm
.
Solution 2 - Windows
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 3 - Windows
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 4 - Windows
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 5 - Windows
Set your PATH
environment variable to C:\Users\YOUR_USERNAME\AppData\Roaming\npm
. This fixed it for me.
Solution 6 - Windows
Just run this command
SET PATH=%AppData%\npm;%PATH%
Solution 7 - Windows
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.