gruntjsgruntfile

Grunt error task "default" not found


When trying to run grunt, I get an error message:

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

I have already found several posts on this topic, and in each of them the problem was a missing comma. But in my case I have no idea what's wrong, I think I didn't miss any comma (btw, this content was copy/pasted from the internet).

module.exports = (grunt) => {
    grunt.initConfig({
        execute: {
            target: {
                src: ['server.js']
            }
        },
        watch: {
            scripts: {
                files: ['server.js'],
                tasks: ['execute'],
            },
        }
    });

    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-execute');
};

What could be the problem?


Solution

  • You didn't registered the default task. Add this after the last loadNpmTask

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

    The second parameter is what you want to be executed from the config, you can put there more tasks.

    Or you can run run existing task by providing the name as parameter in cli.

    grunt execute

    With you config you can use execute and watch. See https://gruntjs.com/api/grunt.task for more information.