grunt icon indicating copy to clipboard operation
grunt copied to clipboard

grunt.registerTask with same name as task definition causes call stack overflow

Open gwicksted opened this issue 11 years ago • 6 comments

Problem occurs when grunt.registerTask('clean', ['clean']); is used alongside the grunt.initConfig({ clean: { ... } }); definition.

Simple example gruntfile.js

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        clean: {
            options: {
                'no-write': true
            },
            build: ["something.js", "something.min.js"]
        }
    });
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.registerTask('clean', ['clean']);
};

Results in the following output:

...

(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral. ... util.js:35 var str = String(f).replace(formatRegExp, function(x) { RangeError: Maximum call stack size exceeded

gwicksted avatar Dec 03 '14 15:12 gwicksted

P.S. I know this configuration may be considered "invalid" but, if so, it should probably result in an error explaining what the issue is.

gwicksted avatar Dec 03 '14 15:12 gwicksted

I solve the problem by renaming the code to: grunt.registerTask('remove', ['clean']);

xuanjinliang avatar Dec 24 '14 03:12 xuanjinliang

I know this is a super old thread, but if somebody else stumbles with the same question from google on it:

The contrib modules, already register tasks with this name, so for example grunt.loadNpmTasks('grunt-contrib-clean'); alone allows already to run grunt clean without any further configuration.

Configs likegrunt.registerTask('clean', ['clean']); are not needed. This comes in only, if you want to configure a multi task as documented here.

Andreas-Schoenefeldt avatar Jun 19 '18 12:06 Andreas-Schoenefeldt

btw, I agree, that grunt should throw at least a warning, if a task name is used twice.

Andreas-Schoenefeldt avatar Jun 19 '18 12:06 Andreas-Schoenefeldt

Wasted an hour for this.

Rishi0405 avatar Sep 06 '19 12:09 Rishi0405

Indeed I wasted like 3 hours at 3 am, and almost dropped my branch in desperation. Thankfully I was too tired to issue the command ;D In fact it wasn't showing any error for me, --debug options did nothing

alanalvarado avatar Jan 09 '20 18:01 alanalvarado