Search code examples
javascriptgruntjsgrunt-contrib-watch

Grunt watch not running less after error correction


I've got an issue with Grunt Watch currently not re-running tasks after compilation error correction.

I get the error message, but then after correcting the error, grunt says the file has been changed, but no tasks are run after that point.

Grunt file:

watch: {
        less: {
            files: ['public/assets/less/**/*.less'],
            tasks: ['css'],
            options: {
                atBegin: true,
                nospawn: true
            }
        },
        scripts: {
            files: [
                'public/assets/js/homepage.js'
            ],
            tasks: ['jsApp'],
            options: {
                nospawn: true,
            }
        }
    },

Error log:

>> ParseError: Unrecognised input in public/assets/less/template.less on line 114, column 31:
>> 114         @media screen and (max-width: 767px) {
>> 115             left: 0;
Warning: Error compiling public/assets/less/main.less
// ----- Corrected the file here, saved again -----
>> File "public/assets/less/template.less" changed.

End of file. Nothing after this point.


Solution

  • This is a problem with the grunt-contrib-watch package spawn function, you probably want to remove nospawn. You might want to try version 1.0.0 of grunt watch if you have not already.

    This issue has been discussed before https://github.com/gruntjs/grunt-contrib-watch/issues/58

    Also, note the documentation:

    Not spawning task runs can make the watch more prone to failing so please use as needed.

    In your position I would upgrade first, see that I have the latest version of grunt, grunt watch and grunt less. If that wouldn't solve the problem I would just let it spawn normally.