【问题标题】:Gruntfile.js - Throwing error 'Recursive process.nextTick detected"Gruntfile.js - 抛出错误“检测到递归 process.nextTick”
【发布时间】:2014-05-27 22:30:16
【问题描述】:

我已经根据官方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']);

};

【问题讨论】:

    标签: javascript node.js gruntjs


    【解决方案1】:

    好的。我想到了。而且 dagnabbit,这个错误在我从 thither 复制到这里的同一个 Gruntfile 中。

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

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

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

    【讨论】:

    • 而不是从 jshint 复制和粘贴这些文件来观看,你可以说 files: jshint.files 而不是 files: ['&lt;%= jshint.files %&gt;']
    【解决方案2】:

    所以我知道这个问题已经得到解答,但我将分享我对这个错误的见解,因为它被证明是浪费时间。

    这是我原来的 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
            }
        }
    },
    

    【讨论】:

      猜你喜欢
      • 2014-04-12
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-18
      相关资源
      最近更新 更多