node.js 已安装全局 NPM 包但未找到命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29955217/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Global NPM package installed but command not found
提问by bendulum
I have globally installed two npm packages "download"and "enigmavirtualbox"via command line:
我通过命令行全局安装了两个 npm 包“download”和“enigmavirtualbox”:
npm install -g downloadand
npm install -g engimavirtualbox
npm install -g download和
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.
我正在尝试在批处理文件中使用它们来从我的节点项目中捆绑单个 .exe 文件。对于这两个命令,这些命令会npm list -g <packagename>产生各自的版本输出,与当前的工作目录无关。
However, inside my batch script the commands "download" and "enigmavirtualbox" cannot be found.
但是,在我的批处理脚本中,找不到命令“download”和“enigmavirtualbox”。
Running npm root -gyields C:\Users\<username>\AppData\Roaming\npm\node_modulesand looking inside that folder I can see that folders for both packages are present.
运行npm root -gyieldsC:\Users\<username>\AppData\Roaming\npm\node_modules并查看该文件夹,我可以看到两个包的文件夹都存在。
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
npm root按照此处所述进行更改- 卸载并重新安装软件包
- 添加环境。要指向的变量 NODE_PATH
C:\Users\<username>\AppData\Roaming\npm\node_modules - 添加
C:\Users\<username>\AppData\Roaming\npm\node_modules到 PATH 环境。多变的
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?
同样的设置在我的第二台计算机上工作(都运行 Win7 64 位)。我的节点安装有问题,还是我做错了什么?
回答by bendulum
The executable binaries and .cmd files end up in C:\Users\<username>\AppData\Roaming\npm(minus the node_modulesat the end) so adding that path to the PATH env. variable fixed the issue.
可执行二进制文件和 .cmd 文件以C:\Users\<username>\AppData\Roaming\npm(减去node_modules末尾的)结尾,因此将该路径添加到 PATH env。变量解决了这个问题。
回答by Mr.Noob
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
回答by zloctb
Here more info about this topic : https://medium.com/@alberto.schiabel/npm-tricks-part-1-get-list-of-globally-installed-packages-39a240347ef0
这里有关于这个话题的更多信息: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

