Global NPM package installed but command not found

2019-02-02 22:06发布

问题:

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?

回答1:

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.



回答2:

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


回答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