这看起来很简单,但我似乎无法调试这个错误。我已将此代码作为 /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>
其他一些注意事项:
- 仅使用
--force
更改错误消息的措辞。 - grunt-contrib-jshint 似乎已成功安装在 /node_modules 中(我删除了所有内容并重新运行
npm install
以确保。 - 如果这很重要,我正在 Windows 上运行它。我尝试以普通用户和管理员身份打开命令行。
- 我尝试注释掉该
loadNpmTask
行以查看风帆是否会自动加载它,但仍然得到Warning: Task "jshint" not found.
感谢您提供的任何线索。