Gruntfile.js - Task "default" not found
Asked Answered
O

2

24

Here is my Gruntfile.js

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),

        uglify: {
          options: {
            mangle: true
          }
          build: {
            src: "js/*.js",
            dest: "js/min/script.js"
          }
        }

    });

    grunt.loadNpmTasks("grunt-contrib-uglify");

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

};

Here is my package.json - I have run npm install already, with all of the plugins that I will use in my Gruntfile, grunt-contrib-uglify is among them.

{
  "name": "bootbuckle",
  "version": "0.1.0",
  "engines": {
    "node": ">= 0.10.0"
  },
  "devDependencies": {
    "grunt": "~0.4.2",
    "grunt-contrib-watch": "~0.5.3",
    "grunt-contrib-sass": "~0.6.0",
    "grunt-csscomb": "~2.0.1",
    "grunt-contrib-htmlmin": "~0.1.3",
    "grunt-contrib-imagemin": "~0.4.1",
    "grunt-contrib-uglify": "~0.2.7"
  }
}

When I simply run grunt in the terminal - here is the error

  build: {
  ^^^^^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected identifier
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.

Thanks in advance for any help you may be able to provide.


EDIT Following Matti's guidance I have inserted a missing comma, a new error is now being thrown

Loading "Gruntfile.js" tasks...ERROR
>> ReferenceError: uglify is not defined
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
Ohmage answered 11/1, 2014 at 12:43 Comment(0)
M
33

You missed a comma here:

    uglify: {
      options: {
        mangle: true
      }, // <-------
      build: {
        src: "js/*.js",
        dest: "js/min/script.js"
      }
    }

Edit: as posted by japrescott, you have to define uglify task as string.

grunt.registerTask('default', ["uglify"]);
Munster answered 11/1, 2014 at 12:46 Comment(3)
This is why I like to lead with commas.Coble
Thanks, I inserted the missing comma, btu a new error is now being thrown. Edited the post above to reflect this.Ohmage
This is why I like to lead with a different language.Inspirit
O
12

try it like this

  grunt.registerTask('default', ["uglify"]);
Ovalle answered 11/1, 2014 at 12:45 Comment(1)
A combination of this and Matti's answer fixed it. Ta very much!Ohmage

© 2022 - 2024 — McMap. All rights reserved.