2

I have defined a simple Gruntfile.js per the official instructions and yet I am getting a warning when I run the grunt watch ('$ grunt watch') or grunt default task ('$ grunt ').

The error is:

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

I have read the related StackOverflow question and answer here: grunt throw "Recursive process.nextTick detected", but that didn't resolve my issue.

My Gruntfile.js is:

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    concat: {
      options: {
        separator: ';'
      },
      dist: {
        src: ['client/app/**/*.js'],
        dest: 'client/dist/<%= pkg.name %>.js'
      }
    },
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
      },
      dist: {
        files: {
          'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
        }
      }
    },
    jshint: {
      files: ['client/app/**/*.js', 'server/**/*.js'],
      options: {
        // options here to override JSHint defaults
        globals: {
          jQuery: true,
          console: true,
          module: true, 
          document: true
        }
      }
    },
    watch: {
      files: ['<% jshint.files %>'],
      tasks: ['jshint']
    }
  });

  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-concat');

  grunt.registerTask('default', ['watch']);
  grunt.registerTask('test', ['jshint']);
  grunt.registerTask('build-dev', ['jshint', 'concat']);
  grunt.registerTask('build', ['jshint', 'concat', 'uglify']);

};

Community
  • 1
  • 1
Chad Moore
  • 734
  • 4
  • 15

2 Answers2

3

OK. I figured it out. And dagnabbit, the bug was in the same Gruntfile that I copied hither from thither.

Node did NOT like the watch instructions to reference the jshint.files property and then call the jshint task. So instead, I put the files in explicitly as follows. After changing the following lines (with context):

 watch: {
       files: ['client/app/**/*.js', 'server/**/*.js'],
       tasks: ['jshint']
     }

the grunt watch and default tasks (the default task was performing the watch task), it worked without any warnings!

Chad Moore
  • 734
  • 4
  • 15
  • 1
    rather than copying and pasting those files from jshint to watch, you could say `files: jshint.files` instead of `files: ['<%= jshint.files %>']` – Erik Donohoo May 27 '14 at 22:34
1

So I know this question has been answered, but I'll share my insights into this error as it proved to be a colossal waste of time.

Here's my original Gruntfile:

module.exports = function (grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        watch: {
            dev: {
                files: ['**/*.js', 'public/stylesheets/**/*.scss'],
                tasks: ['express:dev'],
                options: {
                    spawn: false
                }
            }
        },
        express: {
            dev: {
                options: {
                    script: 'server.js',
                    node_env: 'development'
                }
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-express-server');

    grunt.registerTask('default', ['express:dev', 'watch']);
};

In a similar vain to Chad, I resolved the issue by removing js files from my watch task, which restarts Express. The below configuration of the aforementioned task works fine for me:

watch: {
    dev: {
        files: ['public/stylesheets/**/*.scss'],
        tasks: ['express:dev'],
        options: {
            spawn: false
        }
    }
},
James Wright
  • 3,000
  • 1
  • 18
  • 27