5

我根本无法在 Windows 7 上运行 grunt。按照 Grunt 网站 ( http://gruntjs.com/getting-started ) 上的说明,我运行了:

npm uninstall -g grunt-cli
npm uninstall grunt
npm uninstall -g grunt-init

git clone git@github.com:gruntjs/grunt-init-jquery.git c:/Users/me/.grunt-init/jquery

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

之后,运行“grunt”会产生以下输出:

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 的输出是:

npm WARN package.json consolidate@0.9.1 No repository field.
npm WARN package.json jquery-plugin@0.0.0-ignored No repository field.
npm WARN package.json passport-local-examples-login@0.0.0 No repository field.
npm WARN package.json receiptly@0.0.1 No repository field.
npm WARN package.json cookie-signature@1.0.1 No repository field.
npm WARN package.json fresh@0.1.0 No repository field.
npm WARN package.json methods@0.0.1 No repository field.
npm WARN package.json range-parser@0.0.4 No repository field.
npm WARN package.json send@0.1.0 No repository field.
npm WARN package.json pause@0.0.1 No repository field.
npm WARN package.json policyfile@0.0.4 'repositories' (plural) Not supported.
npm WARN package.json Please pick one as the 'repository' field
npm WARN package.json eyes@0.1.8 No repository field.
npm WARN package.json bytes@0.2.0 No repository field.
npm WARN package.json dateformat@1.0.2-1.2.3 No repository field.
npm WARN package.json uid2@0.0.2 No repository field.
C:\Users\me\AppData\Roaming\npm
└─┬ grunt-init@0.2.1
  └── grunt@0.4.1

在当前目录中运行“npm install grunt”会在运行 grunt 时出现相同的错误。

有什么想法吗?我的理解是 grunt-cli 旨在寻找本地 grunt 安装,但我无法弄清楚为什么它找不到它。

4

4 回答 4

5

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

我得到了完全相同的问题。我通过在本地安装 grunt 解决了这个问题。根据 grunt网站

请注意,安装 grunt-cli 不会安装 Grunt 任务运行器!Grunt CLI 的工作很简单:运行已安装在 Gruntfile 旁边的 Grunt 版本。这允许在同一台机器上同时安装多个版本的 Grunt。

所以我只是通过在本地安装 Grunt 来让它工作。

npm install grunt --save-dev

--save :将其添加到您的 package.json 中。

-dev:将其添加为开发依赖项。

于 2015-04-09T19:20:20.597 回答
3

运行命令的目录中必须有一个 Gruntfile.js。还要仔细检查“npm install grunt”是否确实为您提供了一个 node_modules 目录,其中包含一个名为 grunt 的子目录。

于 2013-08-04T07:00:19.773 回答
1

您应该grunt在 GUI 模式下安装。

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

  1. npm install(一旦完成,您就可以看到node_modules根文件夹中的文件夹)

  2. npm install –g grunt-cli(将版本从 ( 更改"version": "minified"Current release("version":"1.11");一旦运行构建,您应该替换为 minified )

  3. grunt build:full

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

于 2015-06-23T07:02:11.170 回答
0

如果上述答案不起作用,那么您可以尝试使用此

rm -rf node_modules/ && npm cache clean && npm install
于 2017-02-14T14:19:09.880 回答