javascript - Windows 7 专业版上的 "Fatal error: Unable to find local grunt."

标签 javascript node.js gruntjs npm installation

如果我想启动 grunt,我会收到以下消息:

c:\repositories\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

运行 grunt 时你会看到:

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\Roaming\npm\grunt -> C:\Users\dev_user\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt
grunt-cli@0.1.13 C:\Users\dev_user\AppData\Roaming\npm\node_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:

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

C:\Users\dev_user>npm ls -g
C:\Users\dev_user\AppData\Roaming\npm
+-- 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\Roaming\npm\grunt 然后推出新电脑

有没有人知道为什么消息 Fatal error: Unable to find local grunt. coming?

最佳答案

安装 grunt-cli 不会安装 Grunt 任务运行器。 grunt-cli 是允许在同一台机器上同时安装多个版本的 Grunt 的命令行界面。

要安装 grunt,您需要通过以下命令将其全局安装:

npm install -g grunt

或在本地通过以下命令:

npm install grunt

您冷读了 official doc 中的 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.

关于javascript - Windows 7 专业版上的 "Fatal error: Unable to find local grunt.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31809653/

相关文章:

gradle - Gradle的com.moowork.gradle.grunt插件

javascript - Grunt 'watch' 命令不起作用

javascript - 单击查找数据属性 - Jquery

javascript - 如何访问元素并删除 Root 于 DOM 中的特定类?

javascript - 单击链接以更改 div 文本,但需要在单击另一个链接时返回原始内容 - js

javascript - Boost::asio::async_read_until 从不调用处理程序

Node.js - 在运行时动态更改 HTTPS 服务器的 SSL 证书

javascript - 调用时未输入 Angular ng-click 函数

node.js - 异步功能不起作用

sass - 为什么 grunt-contrib-compass 有一个 javascriptsDir 参数?