关于gruntjs:“致命错误:无法找到本地咕噜声。”在Windows 7上

“Fatal error: Unable to find local grunt.” on Windows 7

我根本无法在Windows7上工作。按照grunt网站(http://gruntjs.com/getting-started)上的说明,我已经运行:

1
2
3
4
5
6
7
8
9
npm uninstall -g grunt-cli
npm uninstall grunt
npm uninstall -g grunt-init

git clone [email protected]:gruntjs/grunt-init-jquery.git c:/Users/me/.grunt-init/jquery

npm install -g grunt-cli
grunt-init jquery
npm install .

之后,运行"grunt"将生成以下输出:

1
2
3
4
5
6
7
8
9
grunt-cli: The grunt command line interface. (v0.1.9)

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

npm list grunt的输出为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] 'repositories' (plural) Not supported.
npm WARN package.json Please pick one as the 'repository' field
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
C:\Users\me\AppData
oaming
pm
└─┬ [email protected]
  └── [email protected]

在当前目录中运行"npm install grunt"会在运行grunt时产生相同的错误。

有什么想法吗?我的理解是,grunt cli是为了寻找本地的grunt安装,但我不明白为什么找不到它。


我知道问这个问题已经两年了。但是,如果将来有人想要:

我也有同样的问题。我通过在本地安装Grunt来解决这个问题。根据咕噜声的位置,

Note that installing grunt-cli does not install the Grunt task runner!
The job of the Grunt CLI is simple: run the version of Grunt which has
been installed next to a Gruntfile. This allows multiple versions of
Grunt to be installed on the same machine simultaneously.

所以我就在本地安装了Grunt。

1
npm install grunt --save-dev

--保存:将其添加到package.json中。

-dev:作为dev依赖项添加它。


运行命令的目录中必须有gruntfile.js。再次检查"npm install grunt"是否实际为您提供了一个节点模块目录,其中包含一个名为grunt的子目录。


您应该在GUI模式下安装grunt

打开node.jscmd提示符,打开根文件夹,运行以下命令

  • npm install(完成后,可以在根文件夹中看到node_modules文件夹)

  • npm install –g grunt-cli(版本由("version":"minified"改为Current release("version":"1.11");运行build后应替换为minified)

  • grunt build:full

  • 注意:在第一次运行grunt时,版本必须更改。


    如果上述答案不起作用,则可以尝试使用此方法

    1
    rm -rf node_modules/ && npm cache clean && npm install