inhaq
inhaq

Reputation: 356

Task "default" not found. Use --force to continue. Aborted due to warnings

here is my gruntfile.js

var fs = require("fs"),
    browserify = require("browserify"),
    pkg = require("./package.json");

module.exports = function(grunt) {
  grunt.initConfig({
    mochaTest: {
      test: {
        options: {
          style: 'bdd',
          reporter: 'spec'
        },
        src: ['test/unit/*.js']
      }
    },
    pkg: grunt.file.readJSON('package.json'),
    uglify: {
      options: {
        banner: "/*\n" + grunt.file.read('LICENSE') + "*/"
      },
      dist: {
        files: {
          '<%=pkg.name%>-<%=pkg.version%>.min.js': ['<%=pkg.name%>-<%=pkg.version%>.js']
        }
      }
    }
  });

  grunt.registerTask('build', 'build a browser file', function() {
    var done = this.async();

    var outfile = './brain-' + pkg.version + '.js';

    var bundle = browserify('./browser.js').bundle(function(err, src) {
      console.log("> " + outfile);

      // prepend license
      var license = fs.readFileSync("./LICENSE");
      src = "/*\n" + license + "*/" + src;

      // write out the browser file
      fs.writeFileSync(outfile, src);
      done();
    });
  });
  grunt.registerTask('test', 'mochaTest');

  grunt.loadNpmTasks('grunt-mocha-test');
  grunt.loadNpmTasks('grunt-contrib-uglify');
};

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

Warning: Task "default" not found. Use --force to continue. Aborted due to warnings.

After adding --force it shows:

Warning: Task "default" not found. Used --force, continuing. Done, but with warnings.

Upvotes: 1

Views: 9342

Answers (4)

SafeHouse
SafeHouse

Reputation: 162

You forgot to add default task.

add following line after "grunt.registerTask('test', 'mochaTest');" line.

grunt.registerTask('default', ['test', 'build']);

this task will run both 'test' and 'build'. when run "grunt" without any argument.

For more details refer grunt document on task.

Upvotes: 0

Vigneswaran Marimuthu
Vigneswaran Marimuthu

Reputation: 2532

Tasks have to be registered in grunt before they can be executed.

You have registered a build task in your grunt,

grunt.registerTask('build', 'build a browser file', function() {
    var done = this.async();

    var outfile = './brain-' + pkg.version + '.js';

    var bundle = browserify('./browser.js').bundle(function(err, src) {
      console.log("> " + outfile);

      // prepend license
      var license = fs.readFileSync("./LICENSE");
      src = "/*\n" + license + "*/" + src;

      // write out the browser file
      fs.writeFileSync(outfile, src);
      done();
    });
  });

This can be executed by called grunt build.

When you execute grunt, by default, it looks for a task called default, which should be registered.

So, register a default task (same like build task)

grunt.registerTask('default', 'Executed default task', function() {
    ...
});

You can also pass the third parameter as array of registered tasks so that that will be executed if you run grunt.

grunt.registerTask('default', 'Executed default task', [
    'task1',
    'task4',
    'task3',
]);

Now when you execute grunt, all these tasks will be executed in sequence.

Please note that the each task in the tasks array should be registered using grunt.registerTask.

Upvotes: 0

Alexis_A
Alexis_A

Reputation: 234

There is no task called "default" in your gruntfile. Are you trying to run the build task ?

If so, replace this line:

grunt.registerTask('build', 'build a browser file', function() { ...

With this line

grunt.registerTask('default', 'build a browser file', function() { ...

Upvotes: 0

Aniruddha Das
Aniruddha Das

Reputation: 21688

First you need to understand how grunt command work

  1. you define/register a task in your Gruntfile.js
  2. Thenyou call that task from the command prompt

From your grunt file below is a task registered

 grunt.registerTask('build', 'build a browser file', function() {
    var done = this.async();

    var outfile = './brain-' + pkg.version + '.js';

    var bundle = browserify('./browser.js').bundle(function(err, src) {
      console.log("> " + outfile);

      // prepend license
      var license = fs.readFileSync("./LICENSE");
      src = "/*\n" + license + "*/" + src;

      // write out the browser file
      fs.writeFileSync(outfile, src);
      done();
    });
  });

you can then call that task by calling grunt build which will run that task. And when you only run grunt it looks for a task which name is default

As in your grunt file there is no default task defined you command fails.

Upvotes: 0

Related Questions