grunt-contrib-watch Unbound Recursion Error

62 views Asked by At

I get the same error message as this guy:

grunt-contrib-watch causing Maximum call stack size exceeded

When running "grunt watch" on this grunt file:

module.exports = function(grunt) {

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        uglify: {
            options: {
                banner: '//Copyright (c) 2014 <%= pkg.author %>. All Rights Reserved.\n'
                },
            build: {
                files: {
                    "Static/JavaScript/<%= pkg.name %>/AppLogic.Min.js": ["Static/JavaScript/<%= pkg.name %>/AppLogic.js"]
                }
            }
        },
        less: {
            production: {
                options: {
                    cleancss: true
                },
                files: {
                    "Static/Css/<%= pkg.name %>/Style.Min.css": ["Static/Css/<%= pkg.name %>/Style.css"]
                }
            }
        },
        watch: {
            scripts: {
                files: ["Static/JavaScript/<%= pkg.name %>/AppLogic.js"],
                tasks: ["uglify"]
            },
            styles: {
                files: ["Static/Css/<%= pkg.name %>/Style.css"],
                tasks: ["less"]
            }
        }
    });

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

    grunt.registerTask("default", ["uglify", "less"]);
    grunt.registerTask("watch", ["watch"]);
};

Looking at the answer, my problem seems to have a different cause from the other question, but something is definitely wrong.

Running grunt with no params runs fine so "uglify" and "less" seem to be properly constructed.

Running "grunt watch:scripts" or "grunt watch:styles" will cause the error as well.

Any ideas?

PS: grunt/grunt-cli are installed locally to my app, not globally on my machine. Don't think it makes a difference to solve this problem, but for the sake of completeness...

In addition, I get the following warning a bunch of times before the error pops up:

(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.

1

There are 1 answers

0
Magnitus On BEST ANSWER

Ah, the problem was not my "watch" task structure, but rather this line:

grunt.registerTask("watch", ["watch"]);

Naming the task differently from its argument fixed the problem, like so:

grunt.registerTask("watch_", ["watch"]);

Credits to the following answer, sorry for the duplicate:

warning: Recursive process.nextTick detected