【问题标题】:grunt Fatal error: Unable to find local grunt in Yeomangrunt 致命错误:无法在 Yeoman 中找到本地 grunt
【发布时间】:2013-08-09 11:53:24
【问题描述】:

我安装了 yeoman 并启动了官方文档中提供的示例。 我完成了建议的操作

    yo webapp 
    bower install underscore  
    grunt

运行 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

注意 grunt 已经安装了

    npm install -g grunt-cli

    npm install -g grunt

yo 已经在项目根目录中生成了 Gruntfile.js,我正在运行该命令。
package.json 也已生成:

    "name": "testyo",
    "version": "0.0.0",
    "dependencies": {},
    "devDependencies": {
      "grunt": "~0.4.1",
      "grunt-contrib-copy": "~0.4.1",
      "grunt-contrib-concat": "~0.1.3",
      "grunt-contrib-coffee": "~0.6.5",
      "grunt-contrib-uglify": "~0.2.0",
      "grunt-contrib-compass": "~0.2.0",
      "grunt-contrib-jshint": "~0.4.1",
      "grunt-contrib-cssmin": "~0.6.0",
      "grunt-contrib-connect": "~0.2.0",
      "grunt-contrib-clean": "~0.4.0",
      "grunt-contrib-htmlmin": "~0.1.3",
      "grunt-contrib-imagemin": "~0.1.3",
      "grunt-contrib-watch": "~0.4.0",
      "grunt-rev": "~0.1.0",
      "grunt-autoprefixer": "~0.1.20130516",
      "grunt-usemin": "~0.1.10",
      "grunt-mocha": "~0.3.0",
      "grunt-open": "~0.2.0",
      "grunt-svgmin": "~0.1.0",
      "grunt-concurrent": "~0.1.0",
      "matchdep": "~0.1.1",
      "connect-livereload": "~0.2.0"
    },
    "engines": {
      "node": ">=0.8.0"
    }

另外。从根目录

    grunt --version
    grunt-cli v0.1.9

这确认 grunt 可以在每个目录中运行。
有什么想法吗?

【问题讨论】:

    标签: gruntjs yeoman


    【解决方案1】:

    我遇到了同样的问题。

    运行npm install 后,确保在项目的根目录中创建了一个node_modules 文件夹。这是放置“local grunt”的文件夹。如果该文件夹不存在,请检查您的 npm 配置 npm config ls 并确保您有 global=false

    我在这里找到了解决方案:https://stackoverflow.com/a/13449393/1046584

    【讨论】:

      【解决方案2】:
      npm cache clean
      sudo npm install grunt --save-dev
      

      真的对我有用

      【讨论】:

      • 我在 OS X 上——这也修复了我的问题。感谢您的分享,如果没有您的提示,我会搜索更长的时间。对于任何正在阅读并且不熟悉 Grunt 的人 - 也可以安装 Bower。
      【解决方案3】:

      经过一些快速研究,我从grunt documentation 意识到,必须在项目中安装 grunt。我通过运行来做到这一点:

          sudo npm install grunt --save-dev
      

      现在 grunt 可以工作了。

      我还需要跑步:

          npm install
      

      以便加载所有依赖项。

      这解决了我的问题。老实说,我以为 yeoman 会自动完成最后两个步骤。

      如果您有 cmets 或认为有更好的解决方案,请发表评论。

      【讨论】:

      • 搭建脚手架后,Yeoman 会自动调用npm installbower install。就像软件世界中的一切一样,有时会出现错误。出于某种原因,在您搭建脚手架的过程中,该进程必须过早地从错误中逃脱,从而阻止npm install 默认运行。
      • 感谢您的回复。我已经检查了所有源代码:-)。留下我的帖子,以防对 yeoman 的其他人有用。
      • 奇怪,当我将 git 分支从我的非角度分支改回我的角度分支时,我只需要重做 npm install
      • 谢谢。疯狂地试图找出为什么 grunt 不起作用。原来 grunt 和 yeoman 的初始 npm 安装(都试过)没有运行 npm 安装。工作!谢谢!
      • 也为我工作!
      猜你喜欢
      • 2023-03-13
      • 2016-07-24
      • 2016-01-23
      • 2014-04-21
      • 2013-03-19
      • 2019-03-08
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      相关资源
      最近更新 更多