【问题标题】:Grunt "watch" Warning: Path must be a string. Received undefinedGrunt "watch" 警告:路径必须是字符串。收到未定义
【发布时间】:2025-12-22 07:30:11
【问题描述】:

咕噜“看”不想继续。

问题: 运行“监视”任务 等待... 警告:路径必须是字符串。收到未定义

这是 Gruntfile.js 中的 grunt watch:

watch: {
  //Watch files for changes during "grunt serve"
  main: {
    options: {
        livereload: true,
        livereloadOnError: false,
        spawn: false
    },
    files: [createFolderGlobs(['*.js', '*.less','*.html','*.json']), '!src/bower_components/**/*.js', '!src/js/**/*.js', '!_SpecRunner.html','!.grunt'],
    tasks: [] //all the tasks are run dynamically during the watch event handler

  }
},

【问题讨论】:

    标签: javascript gruntjs grunt-contrib-watch


    【解决方案1】:

    我发现了问题。你需要升级 grunt-contrib-jshint。

    我有版本 "grunt-contrib-jshint": "~0.9"

    改为“grunt-contrib-jshint”:“^1.0.0”

    错误现在消失了!

    【讨论】:

      【解决方案2】:

      我在写这个问题时想通了


      当我为这个问题添加标签时,我看到标签 grunt-contrib-watch 并到达:https://github.com/gruntjs/grunt-contrib-watch

      然后这样做:

      $ npm install grunt-contrib-watch --save-dev
      

      ...现在可以了。无论如何,我还是发布了它,因为我在 google 上找不到有关此的内容。

      【讨论】:

      • 对其他人来说,这对我不起作用。 watch 一直安装。它很容易变成别的东西。