Gruntfile.js - 投掷错误'递归process.nextTick检测到"

时间:2014-05-27 22:30:17

标签: javascript node.js gruntjs

我已根据官方instructions定义了一个简单的Gruntfile.js但是当我运行grunt watch('$ grunt watch')或grunt默认任务('$ grunt')时,我收到警告。

错误是:

  

(节点)警告:检测到递归process.nextTick。这将打破   在下一个版本的节点中。请使用setImmediate进行递归   推迟。

我已阅读相关的StackOverflow问题并在此处回答:grunt throw "Recursive process.nextTick detected",但这并未解决我的问题。

我的Gruntfile.js是:

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

};

2 个答案:

答案 0 :(得分:3)

行。我想到了。和dagnabbit一样,这个bug出现在我从thither复制的同一个Grunt文件中。

Node不喜欢观看指令来引用 jshint.files 属性,然后调用 jshint 任务。因此,我将文件明确地放入如下。更改以下行(使用上下文)后:

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

grunt watch和默认任务(默认任务是执行watch任务),它没有任何警告!

答案 1 :(得分:1)

所以我知道这个问题已得到解答,但我会分享我对这个错误的见解,因为事实证明这是一个巨大的浪费时间。

这是我原来的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']);
};

与Chad类似,我通过从我的watch任务中删除js文件解决了这个问题,该任务重启了Express。上述任务的以下配置对我来说很好:

watch: {
    dev: {
        files: ['public/stylesheets/**/*.scss'],
        tasks: ['express:dev'],
        options: {
            spawn: false
        }
    }
},