grunt-contrib-watch导致了“Maximum call stack size exceeded”错误。

3
当我执行clean任务(grunt clean)时,一切正常,但当我运行watch任务(grunt test)时,我遇到了以下错误:
util.js:35
  var str = String(f).replace(formatRegExp, function(x) {
                  ^
RangeError: Maximum call stack size exceeded

这是我的gruntfile

module.exports = (grunt) ->

  grunt.initConfig
    pkg: grunt.file.readJSON('package.json')

    clean: ['tmpDir/']

    watch:
      options:
        spawn: false
      src:
        tasks: ['clean']
        files: [
          src: 'client/assets/strings/en/str.coffee'
        ]

  # plugins
  grunt.loadNpmTasks('grunt-contrib-clean')
  grunt.loadNpmTasks('grunt-contrib-watch')

  # tasks
  grunt.registerTask('test', ['watch'])

这是我的 package.json 文件:

代码如下:

{
  "author": "Your Name <Your Email>",
  "name": "app-name",
  "description": "Application description",
  "version": "0.0.1",
  "homepage": "",
  "repository": {
    "type": "git",
    "url": ""
  },
  "engines": {
    "node": "~0.10.28"
  },
  "scripts": {
    "start": "muffin server"
  },
  "dependencies": {
    "coffee-script": "~1.1.2",
    "express": "~3.0.6",
    "chai": "~1.4.2",
    "underscore": "~1.4.3",
    "wd": "0.0.27"
  },
  "devDependencies": {
    "express": "~3.0.6",
    "grunt": "^0.4.5",
    "grunt-contrib-coffee": "^0.11.1",
    "grunt-contrib-copy": "^0.6.0",
    "grunt-contrib-less": "^0.11.4",
    "grunt-contrib-watch": "^0.6.1",
    "requirejs": "~2.0.1"
  }
}

当我使用--verbose运行时,输出如下: 注意:将基本路径替换为***
Initializing
Command-line options: --verbose

Reading "gruntfile.coffee" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK

Registering "grunt-contrib-clean" local Npm module tasks.
Reading /***/node_modules/grunt-contrib-clean/package.json...OK
Parsing /***/node_modules/grunt-contrib-clean/package.json...OK
Loading "clean.js" tasks...OK
+ clean

Registering "grunt-contrib-watch" local Npm module tasks.
Reading /***/node_modules/grunt-contrib-watch/package.json...OK
Parsing /***/node_modules/grunt-contrib-watch/package.json...OK
Loading "watch.js" tasks...OK
+ watch
Loading "gruntfile.coffee" tasks...OK
+ test

Running tasks: test

Running "test" task

Running "watch" task
Waiting...
Verifying property watch exists in config...OK
Verifying property watch.src.files exists in config...OK
Warning: Object #<Object> has no method 'indexOf'

Running "watch" task
Waiting...
Verifying property watch exists in config...OK
Verifying property watch.src.files exists in config...OK
Warning: Object #<Object> has no method 'indexOf'

... many of these

Running "watch" task
Waiting...
Verifying property watch exists in config...OK
Verifying property watch.src.files exists in config...OK
Warning: Object #<Object> has no method 'indexOf'

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

util.js:35
  var str = String(f).replace(formatRegExp, function(x) {
                      ^
RangeError: Maximum call stack size exceeded

你的监视任务有没有偶然间忽略了node_modules目录? - undefined
@DeadCalimero - 不是这样的。我甚至尝试指定一个特定的文件,但输出结果没有变化。 - undefined
2个回答

5

我终于解决了一个与拼写有关的类似问题。我使用的是

grunt.registerTask('spell', [ 'spell']); 诀窍在于,Grunt似乎不喜欢名字中的重复。当我改用

grunt.registerTask('spellCheck', [ 'spell']); 一切都按照预期工作。

希望这可以帮到你。


这个对我有帮助,谢谢! - undefined
你可能创建了一个与你的常规任务同名的别名任务。请参考:http://gruntjs.com/frequently-asked-questions#why-am-i-getting-a-maximum-call-stack-size-exceeded-error - undefined

4
files属性接受一个文件模式字符串数组。您提供了一个它不知道如何解释的对象。

请更改为:

files: [
  src: 'client/assets/strings/en/str.coffee'
]

转化为:

files: [
  'client/assets/strings/en/str.coffee'
]

很遗憾,这对我来说没有解决问题。 - undefined
1
最终,这确实修复了它。用户在重试时出错。非常感谢 @kyle - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接