grunt-contrib-watch
grunt-contrib-watch copied to clipboard
Infinite loop when using grunt watch with babel require hook
Im trying to use the Babel require hook in my Gruntfile. Everything works fine until I try to use grunt-watch.
Here is an example.
module.exports = function(grunt) {
require('babel/register')({
experimental: true,
extensions: ['.es6'],
});
require('load-grunt-tasks')(grunt);
grunt.initConfig({
mochaTest: {
options: {
reporter: 'spec'
},
src: ['test/**/*.es6'],
},
watch: {
files: ['lib/**/*.es6'],
tasks: ['test']
}
});
grunt.registerTask('test', ['mochaTest']);
};
First a get a bunch of these messages
Running "watch" task
Waiting...
Warning: boolean is not a function
Followed by a bunch of these...
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
and then
RangeError: Maximum call stack size exceeded
@shama example project https://github.com/vladikoff/grunt-watch-issue-babel425
Not seeing what causing this yet...
Adding
require('babel/register')({
experimental: true,
extensions: ['.es6'],
});
breaks things...
What happens when you enable stack? grunt watch --stack
and remove mochaTest from the equation.
node-inspector is a great tool for debugging these things.
My guess is it's from tiny-lr
and specifically this: https://github.com/jshttp/on-finished/blob/master/index.js#L65
FWIW, this kind of bad stuff happens when you globally apply an es6 library. Why not just use babel when you need it instead of applying it everywhere?
the babel require hook above actually will only touch .es6
files
Thats what extensions: ['.es6']
is setting.
So babel shouldn't be touching anything from tiny-lr
FWIW moving the require('babel/register')
to the end of the file seems to work. This does kinda indicate that its babel doing something wrong.
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
mochaTest: {
options: {
reporter: 'spec'
},
src: ['test/**/*.es6'],
},
watch: {
files: ['lib/**/*.es6'],
tasks: ['test']
}
});
grunt.registerTask('test', ['mochaTest']);
require('babel/register')({
experimental: true,
extensions: ['.es6']
});
};
Nice! Thanks!
Thanks @tikotzky. That is very strange though, I'm curious to know where it's getting tripped up.