node.js Windows 8 上的咕噜声:无法识别“咕噜声”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19135561/
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
Grunt on Windows 8: 'grunt' is not recognized
提问by Daniel Attfield
I'm having a problem running Grunt from the command line on my Windows 8 machine.
我在 Windows 8 机器上从命令行运行 Grunt 时遇到问题。
My research indicates the most common solution is to install grunt-cli, since Grunt is no longer global. I also need to make sure I actually install the Grunt task runner, since that's not installed with grunt-cli.
我的研究表明最常见的解决方案是安装 grunt-cli,因为 Grunt 不再是全局的。我还需要确保我确实安装了 Grunt 任务运行器,因为它没有安装在 grunt-cli 中。
Other solutions point to the PATH system environment variable, but that appears to be pointed as I'd expect to:
其他解决方案指向 PATH 系统环境变量,但这似乎是我所期望的:
C:\Users[username]\AppData\Roaming\npm
C:\Users[用户名]\AppData\Roaming\npm
Having done all that, I'm still getting a "'grunt' is not recognized as an internal or external command, operable program or batch file" error message in the CLI. I've tried the following things, uninstalling everything after every attempt:
完成所有这些后,我仍然在 CLI 中收到“'grunt' 未被识别为内部或外部命令、可运行的程序或批处理文件”错误消息。我尝试了以下操作,每次尝试后都卸载了所有内容:
- Installed grunt-cli globally (npm install -g grunt-cli), then grunt at the directory level I want to use it (npm install grunt)
- The same as above, but with the order of installation reversed
- The same as both of the above, but using the Admin Command Prompt
- 全局安装grunt-cli(npm install -g grunt-cli),然后在我想使用的目录级别grunt(npm install grunt)
- 同上,但安装顺序相反
- 与上述相同,但使用管理命令提示符
Am I missing something obvious?
我错过了一些明显的东西吗?
采纳答案by WiredPrairie
Confirm your PATHis correct (and not messed up). Just type PATHfrom the command prompt. There's really no other explanation that makes sense given the error you're describing and the steps you've taken.
确认你PATH是正确的(而不是搞砸了)。只需PATH从命令提示符键入。鉴于您描述的错误和您采取的步骤,真的没有其他解释有意义。
Normally, using the where gruntcommand would have found grunt.cmdin your path if npmis installed correctly and it has been properly added to the system path.
通常,如果安装正确并且已正确添加到系统路径中,则使用该where grunt命令会grunt.cmd在您的路径中找到npm。
回答by Rik Leigh
I've not had any issues with grunt on several different windows 8 machines.
我在几台不同的 Windows 8 机器上没有遇到任何 grunt 问题。
If you open the folder: C:\Users\[username]\AppData\Roaming\npm
如果打开文件夹: C:\Users\[username]\AppData\Roaming\npm
Do you have a file named grunt.cmdin this folder?
你有一个grunt.cmd在这个文件夹中命名的文件吗?
If not I'd maybe try npm install -g grunt-cliagain, maybe from an elevated command prompt.
如果不是,我可能会再试npm install -g grunt-cli一次,也许是从提升的命令提示符。
If this exists and you have C:\Users\[username]\AppData\Roaming\npmin your PATH environment variable then typing grunt from a command prompt should work.
如果这存在并且您C:\Users\[username]\AppData\Roaming\npm的 PATH 环境变量中有,那么从命令提示符输入 grunt 应该可以工作。
Silly question, have you tried closing the command prompt and opening a new one?
愚蠢的问题,您是否尝试过关闭命令提示符并打开一个新的命令提示符?
回答by Daniel A.A. Pelsmaeker
- Close all Command Prompt instances.
- Start a new Command Prompt instance.
- Type
PATHEnterand verify ifC:\Users\Username\AppData\Roaming\npmis part of the path. - If not, you need to log off and on again,
or close the Command Prompt and restart theexplorerprocess. In the Command Prompt, type
where gruntEnter.
You're good if it reports:C:\Users\Username\AppData\Roaming\npm\grunt C:\Users\Username\AppData\Roaming\npm\grunt.cmdOtherwise, you have to reinstall the
grunt-clipackage if it reports:INFO: Could not find files for the given pattern(s).
- 关闭所有命令提示符实例。
- 启动一个新的命令提示符实例。
- 键入
PATHEnter并验证是否C:\Users\Username\AppData\Roaming\npm是路径的一部分。 - 如果没有,您需要注销并再次登录,
或者关闭命令提示符并重新启动该explorer过程。 在命令提示符中,键入
where gruntEnter。
如果它报告:C:\Users\Username\AppData\Roaming\npm\grunt C:\Users\Username\AppData\Roaming\npm\grunt.cmd否则,您必须重新安装
grunt-cli软件包,如果它报告:INFO: Could not find files for the given pattern(s).
Apparently, programs that change the PATHenvironment variable must broadcast a WM_SETTINGCHANGEmessage. The Windows' Systemsettings window does it correctly when you change the PATHvariable, but the NPM installer doesn't. That's why you have to restart explorer (or log off or restart, which has the same effect).
显然,改变PATH环境变量的程序必须广播一条WM_SETTINGCHANGE消息。当您更改变量时,Windows 的系统设置窗口会正确执行此操作PATH,但 NPM 安装程序不会。这就是为什么您必须重新启动资源管理器(或注销或重新启动,这具有相同的效果)。
回答by Tom Gillard
I know this has been answered but I thought I'd offer my step by step solution for windows 8.
我知道这已经得到了回答,但我想我会为 Windows 8 提供我的分步解决方案。
First thing I checked was the PATH in my laptops Environment Variables (Right click my computer > properties > advanced system settings > Environment Variables)
我检查的第一件事是笔记本电脑环境变量中的 PATH(右键单击我的电脑 > 属性 > 高级系统设置 > 环境变量)
It wasn't listed in there so I added a new variable in User variables (so it was specific only to my user account)
它没有列在那里,所以我在用户变量中添加了一个新变量(所以它只针对我的用户帐户)
In the new user variable prompt I entered the following;
在新的用户变量提示中,我输入了以下内容;
Variable Name: PATH
Variable Value: %USERPROFILE%\AppData\Roaming\npm
Quit command prompt, repoened, navigated to my projects directory and tried running gruntagain and... SUCCESS!
退出命令提示符,repoened,导航到我的项目目录并尝试grunt再次运行......成功!
回答by jsan
I had the same issue.
我遇到过同样的问题。
I tried different things:
我尝试了不同的事情:
- Restart computer
- Deleted the grunt folder and ran
- 重启电脑
- 删除了 grunt 文件夹并运行
npm install -g grunt -cli
npm install -g grunt -cli
Didn't work.
没用。
Finally tried:
最后尝试:
npm install -g grunt-cli
npm install -g grunt-cli
Worked perfectly.
完美地工作。
Tried
试过
where grunt
咕噜声
and I saw 2 locations where it was found.
我看到了 2 个发现它的地方。
回答by JP Bala Krishna
I was facing the same problem on windows 8
我在 Windows 8 上遇到了同样的问题
I have added ' %APPDATA%\npm ' to the path variable . It has been working fine.
我已将“%APPDATA%\npm”添加到路径变量中。它一直运行良好。
回答by kadalamittai
some times NPM install corrupts the basic windows path. i usually have a copy of my own version of PATH mainted separately. every week or on some installs i manually configure and update the %PATH% variable.
有时 NPM 安装会破坏基本的 Windows 路径。我通常有一份我自己版本的 PATH 单独维护。每周或在某些安装中,我手动配置和更新 %PATH% 变量。
Basically Grunt.cmd is not availbe through %PATH% variable.
基本上 Grunt.cmd 不能通过 %PATH% 变量使用。
回答by Chekit
I have stucked with problem on Windows 8, that after install grunt-cli I've always got "command not found" while I'm tried to check grunt -vor where grunt. So I've added to enviroment PATH this path C:\Program Files (x86)\Git\localand run grunt.cmd from that folder (you need to look in node_modules folder here). And after reloading my terminal everything started to work.
我一直在 Windows 8 上遇到问题,在安装 grunt-cli 后,我总是在尝试检查grunt -v或where grunt. 因此,我已将此路径添加到环境 PATHC:\Program Files (x86)\Git\local并从该文件夹运行 grunt.cmd (您需要在此处查看 node_modules 文件夹)。重新加载我的终端后,一切都开始工作了。
回答by sebbulon
Same happened to me and here was the solution:
Have you got 2 different versions of Node.JS installed?
Maybe Nodist?
This means you likely got NPM installed twice which will install the commands into 2 different folders:
Once into C:\Users\<user>\AppData\Roaming\npmand once into C:\dev\nodist\bin\bin.
我也遇到了同样的情况,这是解决方案:您是否安装了 2 个不同版本的 Node.JS?也许Nodist?这意味着您可能安装了两次 NPM,这会将命令安装到 2 个不同的文件夹中:一次进入 C:\Users\<user>\AppData\Roaming\npm和一次进入C:\dev\nodist\bin\bin.
C:\dev\nodist\bin\binwasn't on my path variable so I added it, and I removed the Node.JS version I didn't want to use.
C:\dev\nodist\bin\bin不在我的路径变量中,所以我添加了它,并删除了我不想使用的 Node.JS 版本。
回答by winblood
If you have no grunt.cmd file created by npm, make sure that you do not have a .npmrcin your home directory with: bin-links=falsein it.
如果您没有 npm 创建的 grunt.cmd 文件,请确保您的主目录中没有.npmrc,其中包含:bin-links=false。

