gruntjs - 咕噜 fatal error : Unable to find local grunt in Yeoman

标签 gruntjs yeoman

我安装了 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 可以在每个目录中运行。
有什么想法吗?

最佳答案

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

    sudo npm install grunt --save-dev

现在 grunt 可以工作了。

我还需要运行:

    npm install

以便加载所有依赖项。

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

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

关于gruntjs - 咕噜 fatal error : Unable to find local grunt in Yeoman,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18114666/

相关文章:

node.js - 找不到模块 'generator-jhipster'

angularjs - 如何使用 ngmin 注释 angularjs 文件并使用min 生成 dist 文件

javascript - 扩展 Angular yeoman 生成器

javascript - fixture 不会在 Karma 中加载

angularjs - Jasmine 匹配器函数未在 angularjs/karma 单元测试中加载

javascript - Grunt Uglify 通配符和版本控制

gruntjs - Yeoman 生成器自动运行测试

angularjs - Yeoman Angular 应用程序,grunt watch .less 文件

ruby-on-rails - 可以自动将我所有的js包含在index.html中吗?

javascript - 将 js 文件替换为相应的缩小版本