【问题标题】:"Fatal error: Unable to find local grunt." on windows7 professional“致命错误:无法找到本地咕噜声。”在 Windows 7 专业版上
【发布时间】:2015-10-26 21:07:18
【问题描述】:

如果我想启动 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

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

操作系统:windows 7 Professional
npm -版本:1.3.5
节点--版本: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. 吗?

【问题讨论】:

    标签: javascript node.js gruntjs npm installation


    【解决方案1】:

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

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

    npm install -g grunt
    

    或通过以下命令在本地:

    npm install grunt
    

    您在official doc 中冷读了有关grunt-cli 的信息

    @Matthew Bakaitis 的注释:

    不鼓励全局安装 grunt

    这是一个很好的做法,因为 grunt-cli 首先加载一个全局版本(如果我记得的话)。如果项目需要特定版本的 grunt,全局安装会破坏这一点。此外,如果您的构建依赖于 grunt,为什么不将其作为依赖项安装并在 package.json 中列出呢?如果您没有在 package.json 中添加依赖项,则有一个很大的假设是其他开发人员或目标系统将全局安装 grunt。考虑到 grunt 的使用情况,我想不出在很多情况下全局安装会更好。

    【讨论】:

    • 仅供参考:全局安装 gruntdiscouraged
    • @MatthewBakaitis 你能解释一下为什么吗?
    • 这是一个很好的做法,因为grunt-cli 首先加载一个全局版本(如果我记得的话)。如果项目需要特定版本的 grunt,全局安装会破坏这一点。此外,如果您的构建依赖于 grunt,为什么不将其作为依赖项安装并在 package.json 中列出呢?如果您没有在package.json 中添加依赖项,则有一个很大的假设是其他开发人员或目标系统将全局安装 grunt。考虑到 grunt 的使用情况,我想不出在很多情况下全局安装会更好。
    • 谢谢。我已将您的注释添加到答案中。
    【解决方案2】:

    我的问题的解决方案。 就我而言,我有一位同事找到了解决方案。 我安装了两个版本的 NodeJS,一个较旧的 1.0.35 和当前的 1.2.7 版本。 在 Windows 卸载程序中,只有一个版本可见! 在我卸载了那个版本和所有目录之后,即旧版本和新版本在当前版本矛盾安装后被删除,因为我可以命令应该 npm install 打电话。 之后,我可以轻松地咕噜咕噜地打电话,它工作正常。

    【讨论】:

      猜你喜欢
      • 2013-08-05
      • 2013-03-07
      • 2014-07-25
      • 1970-01-01
      • 2012-12-05
      • 2015-09-16
      • 2015-05-25
      • 2013-03-15
      • 2017-04-30
      相关资源
      最近更新 更多