Grunt Warning: Task "concat" not found

4.6k views Asked by At

I'm trying to get started with a simple Grunt example, but I'm running into an issue with grunt-contrib-concat.

Here's my Gruntfile.js:

$ cat Gruntfile.js 
module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    concat: {
      options: {
        separator: ';'
      },
      dist: {
        src: ['src/**/*.js'],
        dest: 'dist/<%= pkg.name %>.js'
      }
    }
  });

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

  grunt.registerTask('default', ['concat']);

and my package.json:

$ cat package.json 
{
  "name": "Linker",
  "version": "0.0.0",
  "description": "A test project that is meant to be a dependency",
  "repository": {
    "type": "git",
    "url": "git://github.com/jonbri/Linker.git"
  },
  "main": "src/index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
      "grunt-contrib-concat": "*"
  },
  "author": "",
  "license": "ISC"
}

Running npm install doesn't show any obvious errors:

$ npm install
$ ls node_modules/
grunt  grunt-contrib-concat

Here is what my directory structure looks like:

$ ls
Gruntfile.js  node_modules  package.json  README.md  src
$ ls src
index.js

When I run grunt concat I get this:

$ grunt concat
Loading "concat.js" tasks...ERROR
>> Error: Cannot find module 'ansi-styles'
Warning: Task "concat" not found. Use --force to continue.

Aborted due to warnings.

My setup:

Lubuntu 12.10, node: v0.10.25, npm: 1.4.21, grunt-cli: v0.1.13, grunt: v0.4.5

Am I missing something?

1

There are 1 answers

3
michelem On BEST ANSWER

You should run it as: grunt without concat as the task is the default one. No arguments are needed to run it. So the command to launch becomes simply:

grunt

Use this to install grunt-contrib-concat:

npm install grunt-contrib-concat --save-dev

Package.json should have something like this:

"devDependencies": {
  "grunt-contrib-concat": "^0.5.1"
},