Search code examples
javascriptnode.jsgruntjsecmascript-6traceur

Grunt can not find task


Something went wrong with my grunt config and I can not figure out what. Giver part of my grunfile.js

grunt.initConfig({
    traceur: {
        options: {
            blockBinding: true
        },
        custom: {
            files: [{
                expand: true,
                cwd: 'public/js',
                src: ['*.js'],
                dest: 'public/components'
            }]
        }
    },
    watch: {
        js: {
            files: ['public/js/*.js'],
            tasks: [' traceur' ]
        }
    }
    /* ... */
});

I register two tasks from above:

grunt.registerTask('default', ['watch']);
grunt.registerTask('tr', ['traceur']);

While running grunt tr everything is fine. But when watch task tries to run traceur after code changed I'll get error:

>> File "public/js/app.js" changed. 
Fatal error: Task " traceur" not found

Why does not grunt find traceur task?


Solution

  • You have a leading white space in front of the task in the watch section.

    watch: {
        js: {
            files: ['public/js/*.js'],
            tasks: [' traceur' ]
        }
    }
    

    Change to:

    watch: {
        js: {
            files: ['public/js/*.js'],
            tasks: ['traceur']
        }
    }