已安装 Node JS NPM 模块但无法识别命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30710550/
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
Node JS NPM modules installed but command not recognized
提问by Wishnu
Node JS and NPM was working well before. Recently I have re-installed the Node JS, NPM and the problem started. After I install a module like example npm install -g bower, the module gets installed successfully but bower -vgives
Node JS 和 NPM 之前运行良好。最近我重新安装了Node JS,NPM,问题开始了。在我安装了一个像 example 那样npm install -g bower的模块后,该模块被成功安装但bower -v给出
'bower' is not recognized as an internal or external command, operable program or batch file.
'bower' 不是内部或外部命令,也不是可运行的程序或批处理文件。
I have checked the installation path
C:\Users\XXXXX\AppData\Roaming\npm\node_moduleswhich has all the old installed modules. I have tried to uninstall them and reinstall the modules, but still I am getting the same error.
我已经检查了C:\Users\XXXXX\AppData\Roaming\npm\node_modules包含所有旧安装模块的安装路径
。我尝试卸载它们并重新安装模块,但仍然遇到相同的错误。
Even I have deleted the entire folder and installed all the modules again but the result is same.
即使我已经删除了整个文件夹并再次安装了所有模块,但结果是一样的。
I don't know why I am getting this error after reinstalling NodeJS NPM.
我不知道为什么在重新安装 NodeJS NPM 后会出现此错误。
Any help is greatly appreciated. Thanks in advance.
任何帮助是极大的赞赏。提前致谢。
回答by James Gentes
I had this same problem and fixed it by adding the 'npm' directory to my PATH:
我遇到了同样的问题,并通过将“npm”目录添加到我的 PATH 来修复它:
Right click 'My Computer' and go to 'Properties > Advanced System Settings > Environment Variables'.
右键单击“我的电脑”,然后转到“属性 > 高级系统设置 > 环境变量”。
Double click on PATH under the 'User variables for Username' section, and add 'C:\Users\username\AppData\Roaming\npm' obviously replacing 'username' with yours. Based on comments below, you may need to add it to the top/front of your path.
双击“用户名的用户变量”部分下的 PATH,并添加“C:\Users\username\AppData\Roaming\npm”,显然将“username”替换为您的。根据下面的评论,您可能需要将其添加到路径的顶部/前面。
Restart your console window or IDE and you should get a response from the bower command.
重新启动您的控制台窗口或 IDE,您应该会收到来自 bower 命令的响应。
回答by julianpitt
I had the same problem as well but installed it globally so the other answers didn't work.
我也遇到了同样的问题,但在全球范围内安装了它,因此其他答案不起作用。
The nodeJS install may not have added npm to your PATH so it's not recognised globally.
nodeJS 安装可能没有将 npm 添加到您的 PATH 中,因此无法全局识别。
Firstly: To figure out if you installed globally or for current user
首先:确定您是全局安装还是当前用户安装
If there is an npm folder at "C:\Users(your username)\AppData\Roaming\npm" you've installed it for the current user
如果在 "C:\Users(your username)\AppData\Roaming\npm" 有一个 npm 文件夹,你已经为当前用户安装了它
If there is an npm folder at "C:\Program Files\nodejs\node_modules\npm" or "C:\Program Files(x86)\nodejs\node_modules\npm" you've installed it globally for all users to access
如果在 "C:\Program Files\nodejs\node_modules\npm" 或 "C:\Program Files(x86)\nodejs\node_modules\npm" 有一个 npm 文件夹,你已经全局安装了它供所有用户访问
Secondly: To add it to the Path
其次:将其添加到路径
- Right click My Computer
- Click on properties down the bottom
- Click on Advanced System Settings in the left bar
- Click on Environment Variables down the bottom
- 右键单击我的电脑
- 点击底部的属性
- 单击左侧栏中的高级系统设置
- 单击底部的环境变量
Now depending whether you installed globally or for the current user will determine which PATH variable you are updating and with what path location
现在取决于您是全局安装还是为当前用户安装将确定您要更新的 PATH 变量以及路径位置
Local
当地的
- Double click on PATH under 'user variables' section
- Add "C:\Users(your username)\AppData\Roaming\npm" without the quotes
- 双击“用户变量”部分下的 PATH
- 添加 "C:\Users(your username)\AppData\Roaming\npm" 不带引号
Global
全球的
- Double click on PATH under 'user variables' section
- Add "C:\Program Files\nodejs" without the quotes (or with (x86))
- 双击“用户变量”部分下的 PATH
- 添加不带引号的“C:\Program Files\nodejs”(或带 (x86))
Finally
最后
Close all terminals or programs that aren't able to find npm and open them up again
关闭所有找不到 npm 的终端或程序,然后再次打开它们
回答by S.Droid
If the package is successfully installedand still shows the message "'npm' is not recognized as an internal or external command, operable program or batch file."
如果软件包已成功安装但仍显示消息“ 'npm' 不是内部或外部命令、可运行的程序或批处理文件。”
- Click windows start button.
- Look for "ALL APPS", you will see Node.js and Node.js Command prompt there.
- You can run the Node.js Command promptas administrator and soon as its run it will show the message "Your environment has been set up for using Node.js 6.3.0 (x64) and npm."
- 单击 Windows 开始按钮。
- 寻找“ ALL APPS”,你会在那里看到 Node.js 和 Node.js 命令提示。
- 您可以以管理员身份运行Node.js 命令提示符,一旦运行,它将显示消息“您的环境已设置为使用 Node.js 6.3.0 (x64) 和 npm。”
回答by Mohammad Arif
Run npm config get prefixand check the correct npm path first and append the output to the PATH using command or adding manually.
首先运行npm config get prefix并检查正确的 npm 路径,然后使用命令或手动添加将输出附加到 PATH。
npm config get prefix C:\mydev\tools\npm\npm
set PATH=%PATH%;C:\mydev\tools\npm\npm
npm config get prefix C:\mydev\tools\npm\npm
set PATH=%PATH%;C:\mydev\tools\npm\npm
回答by ThadeuLuz
You should probably check if your node/bin directory is in your PATH variable. Look for it where you've been installing these global modules.
您可能应该检查您的 node/bin 目录是否在您的 PATH 变量中。在您安装这些全局模块的位置查找它。
Im not on windows, so I cant tell you the exact command, but you can check these variables navigating to [Control Panel -> System -> Advanced -> Environment Variables] or something like this.
我不在 Windows 上,所以我不能告诉你确切的命令,但是你可以检查这些变量导航到 [控制面板 -> 系统 -> 高级 -> 环境变量] 或类似的东西。
I hope this helped.
我希望这有帮助。
回答by nowhere
In my case the npm folder was already in the PATH variable.
在我的情况下,npm 文件夹已经在 PATH 变量中。
If after trying everything else, you also still can't make it work, try to delete the folder from the PATH variable and put it at the beginning of the list.
如果在尝试了所有其他方法后,您仍然无法使其工作,请尝试从 PATH 变量中删除该文件夹并将其放在列表的开头。

