0

这看起来很简单,但我似乎无法调试这个错误。我已将此代码作为 /tasks/config/jshint.js 添加到我的 Sails API

module.exports = function(grunt) {
  console.log(1);
  grunt.config.set('jshint', {
    files: {
      src: ['api/services/*.js', 'api/policies/*.js', 'api/controllers/*.js']
    }
  });
  console.log(2);
  grunt.loadNpmTask('grunt-contrib-jshint');
  console.log(3);
};

现在,当我执行任何 grunt 任务时,我会收到一条错误消息(但旧任务仍然成功执行)。

C:\dev\fo-rest-api>grunt aglio
1
2
Loading "Gruntfile.js" tasks...ERROR
>> TypeError: undefined is not a function

Running "aglio:your_target" (aglio) task
...
Done, without errors.

当我运行 jshint 任务时,我得到相同的加载错误并且任务被中止。

C:\dev\fo-rest-api>grunt jshint
1
2
Loading "Gruntfile.js" tasks...ERROR
>> TypeError: undefined is not a function
Warning: Task "jshint" not found. Use --force to continue.

Aborted due to warnings.

C:\dev\fo-rest-api>

其他一些注意事项:

  1. 仅使用--force更改错误消息的措辞。
  2. grunt-contrib-jshint 似乎已成功安装在 /node_modules 中(我删除了所有内容并重新运行npm install以确保。
  3. 如果这很重要,我正在 Windows 上运行它。我尝试以普通用户和管理员身份打开命令行。
  4. 我尝试注释掉该loadNpmTask行以查看风帆是否会自动加载它,但仍然得到Warning: Task "jshint" not found.

感谢您提供的任何线索。

4

1 回答 1

0

答案很简单。我以某种方式删除sgrunt.loadNpmTasks. 当我重新添加它时,一切正常。

我希望有某种语法突出显示,对于像 grunt 这样的常见包可以识别这种错字......

于 2016-03-03T01:32:10.460 回答