grunt.registerTask with same name as task definition causes call stack overflow
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
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.
I solve the problem by renaming the code to: grunt.registerTask('remove', ['clean']);
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.
btw, I agree, that grunt should throw at least a warning, if a task name is used twice.
Wasted an hour for this.
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