Grunt concat failing with “Unable to find local grunt”

纵饮孤独 提交于 2019-12-06 13:45:22

问题


I have installed Grunt like so `npm install -g grunt-cli successfully.

I have also installed the grunt-contrib-concat libary succesfully like so: npm install grunt-contrib-concat --save-dev

I have created a package.json:

{
  "name": "my-project-name",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-jshint": "~0.1.1",
    "grunt-contrib-nodeunit": "~0.1.2"
  }
}

and a Gruntfile.js:

module.exports = function(grunt) {

grunt.initConfig({
  pkg: grunt.file.readJSON('package.json'),
  concat: {
    options: {
      separator: ';'
    },
    dist: {
      src: ['src/init.js', 'src/Game.js', 'ui/Ui.js', 'ui/AddBTS.js', 'ui/Toolbar.js'],
      dest: 'built.js'
    }
  }
});

grunt.loadNpmTasks('grunt-contrib-concat');

};

Now when I run grunt concat I get the following error:

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:

This is my first time using Grunt and I've been trying to solve this problem for over 2 hours now. Please could someone help me and advise what I've not set up correctly.

Thanks in advance!


回答1:


It's likely that Grunt is not installed locally in your project folder (which is different than grunt-cli). You have it in your package.json so try doing npm install or alternately npm install grunt.

For more information see the getting started page:

Note that installing grunt-cli does not install the grunt task runner! The job of the grunt CLI is simple: run the version of grunt which has been installed next to a Gruntfile. This allows multiple versions of grunt to be installed on the same machine simultaneously.



来源:https://stackoverflow.com/questions/15694121/grunt-concat-failing-with-unable-to-find-local-grunt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!