grunt-contrib-watch icon indicating copy to clipboard operation
grunt-contrib-watch copied to clipboard

Infinite loop when using grunt watch with babel require hook

Open sethpollack opened this issue 9 years ago • 8 comments

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

sethpollack avatar Mar 26 '15 19:03 sethpollack

@shama example project https://github.com/vladikoff/grunt-watch-issue-babel425

Not seeing what causing this yet...

vladikoff avatar Mar 26 '15 19:03 vladikoff

Adding

  require('babel/register')({
    experimental: true,
    extensions: ['.es6'],
  });

breaks things...

vladikoff avatar Mar 26 '15 19:03 vladikoff

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.

shama avatar Mar 26 '15 19:03 shama

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?

shama avatar Mar 26 '15 19:03 shama

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

tikotzky avatar Mar 26 '15 20:03 tikotzky

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']
  });

};

tikotzky avatar Mar 26 '15 20:03 tikotzky

Nice! Thanks!

sethpollack avatar Mar 26 '15 20:03 sethpollack

Thanks @tikotzky. That is very strange though, I'm curious to know where it's getting tripped up.

shama avatar Mar 26 '15 20:03 shama