javascript - Gruntfile.js - 抛出错误 'Recursive process.nextTick detected"

标签 javascript node.js gruntjs

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

错误是:

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

我已阅读相关的 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']);

};

最佳答案

好的。我想到了。还有 dagnabbit,这个 bug 就在我从 thither 复制的同一个 Gruntfile 中。 .

Node 不喜欢 watch 指令来引用 jshint.files 属性,然后调用 jshint 任务。因此,我将文件显式放入,如下所示。更改以下行后(带上下文):

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

grunt 监视和默认任务(默认任务是执行监视任务),它工作时没有任何警告!

关于javascript - Gruntfile.js - 抛出错误 'Recursive process.nextTick detected",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23900010/

相关文章:

node.js - Node.js 上的条件断点

gruntjs - 使用 Yeoman/Grunt 项目运行 Apache

javascript - 如何读取新标签页location.href.match?使用 JavaScript

javascript - Ajax 选择框未填充

javascript - 使用 Node 和 ejs 时调用外部 api 端点并获取用户的详细信息

angularjs - 使用 Grunt 后在 Angular 项目中包含外部 JS 文件(通过 Yeoman)

javascript - 仅在最近修改的文件上运行 grunt-contrib-jshint

javascript - 选择的 "Multiple Select"

node.js - node_modules目录下的vscode调试代码

node.js - mongoose.connect 在开 Jest 测试后留下打开的句柄