关于javascript:“致命错误:无法找到本地咕噜声。”在windows7专业版上

“Fatal error: Unable to find local grunt.” on windows7 professional

如果我想开始咕哝,我会收到以下消息:

1
2
3
4
5
6
7
8
9
10
11
c:
epositories\kunde_1\themes-projekt_1\projekt_1-responsive\source>grunt
grunt-cli: The grunt command line interface. (v0.1.13)

Fatal error: Unable to find local grunt.

If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:

http://gruntjs.com/getting-started

当运行咕噜声时,你会看到:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
C:\Users\dev_user>npm install -g grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli
npm http 304 https://registry.npmjs.org/grunt-cli
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/findup-sync
npm http GET https://registry.npmjs.org/resolve
npm http 304 https://registry.npmjs.org/nopt
npm http 304 https://registry.npmjs.org/findup-sync
npm http 304 https://registry.npmjs.org/resolve
npm http GET https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/lodash
npm http 304 https://registry.npmjs.org/abbrev
npm http 304 https://registry.npmjs.org/glob
npm http 304 https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/minimatch
npm http 304 https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http 304 https://registry.npmjs.org/lru-cache
npm http 304 https://registry.npmjs.org/sigmund
C:\Users\dev_user\AppData
oaming
pm\grunt -> C:\Users\dev_user\AppData
oaming
pm
ode_modules\grunt-cli\bin\grunt
grunt-cli@0.1.13 C:\Users\dev_user\AppData
oaming
pm
ode_modules\grunt-cli
+-- nopt@1.0.10 (abbrev@1.0.7)
+-- resolve@0.3.1
+-- findup-sync@0.1.3 (lodash@2.4.2, glob@3.2.11)

在用户目录中输入grunt:

1
2
3
4
5
6
7
8
9
10
C:\Users\dev_user>grunt
grunt-cli: The grunt command line interface. (v0.1.13)

Fatal error: Unable to find local grunt.

If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:

http://gruntjs.com/getting-started

但当我进入项目目录时,同样的信息也会出现!

operating system: windows 7 Professional
npm -version: 1.3.5
node --version: v0.10.15

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
C:\Users\dev_user>npm ls -g
C:\Users\dev_user\AppData
oaming
pm
+-- coffee-script@1.9.3
+-- grunt-cli@0.1.13
  +-- findup-sync@0.1.3
  | +-- glob@3.2.11
  | | +-- inherits@2.0.1
  | | +-- minimatch@0.3.0
  | |   +-- lru-cache@2.6.5
  | |   +-- sigmund@1.0.1
  | +-- lodash@2.4.2
  +-- nopt@1.0.10
  | +-- abbrev@1.0.7
  +-- resolve@0.3.1

我设置的环境变量:

变量名:grunt路径:C:\Users\dev_user\AppData
oaming
pm\grunt
。然后推出了新电脑

有人知道消息致命错误的原因吗:找不到本地呼噜声。来了?


安装grunt-cli不会安装grunt任务运行程序。grunt-cli是命令行接口,允许在同一台机器上同时安装多个版本的grunt。

要安装grunt,需要通过以下命令全局安装它:

1
npm install -g grunt

或通过以下命令在本地执行:

1
npm install grunt

你在官方文件中读到过关于grunt-cli

来自@matthew bakaitis的注释:

Installing grunt globally is discouraged

It's good practice as grunt-cli loads a global version first (if I recall). If a project was expecting a specific version of grunt, installing globally would break this. Also, if you are depending upon grunt for your builds, why wouldn't you install it as a dependency and list it in package.json? There's a huge assumption that other developers or the target system will have grunt installed globally if you aren't adding as a dependency in package.json. Given the usage situations for grunt, I can't think of many situations where a global install would be better.


我的问题的解决办法。在我的情况下,我有一个同事找到了解决办法。我安装了两个版本的nodejs,一个旧的1.0.35版本和当前的1.2.7版本。在Windows卸载程序中,只有一个版本可见!在我卸载了那个版本和所有目录之后,也就是说,旧版本和新版本在当前版本被冲突安装之后被删除,因为我可以命令应该NPM安装调用。在那之后,我可以轻松地咕哝着打电话,它工作正常。