Grunt警告:未找到任务“watch”

21

Gruntfile.js:

grunt.initConfig({
 watch: {
  compass: {
    files: [
      'app/styles/**/*.{scss,sass}'
    ],
    tasks: 'compass reload'
  },
.....
grunt.registerTask('dev', 'watch');

当我运行时

grunt dev 

我遇到了错误。

Warning: Task "watch" not found. Use --force to continue. 

我使用的是grunt-cli v0.1.6和grunt v0.4.0,已经安装了grunt-contrib-watch。

6个回答

50

你不必安装整个contrib-package。有一个单独的包供观看使用。

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

最后:

grunt.loadNpmTasks('grunt-contrib-watch');

5
Gruntеӣўйҳҹе»әи®®дҪҝз”Ёеҗ„дёӘжЁЎеқ—иҖҢйқһgrunt-contribпјҢиҝҷжҳҜжӯЈзЎ®зҡ„еҒҡжі•гҖӮ - Kyle Robinson Young

9
好的。
npm install grunt-contrib --save-dev

在grunt.js的最后一行之前添加此行:

grunt.loadNpmTasks('grunt-contrib');

此外,我必须安装了Ruby...

5
等等,你需要安装整个 grunt-contrib 库吗?这有很多依赖项。这怎么是最佳解决方案? - Arron S
1
这可能不是最好的解决方案。当然,我也没有使用所有这些功能。 - Serge

0

我知道这个问题很旧了,但是它还没有得到适当的回答,因为Serge说:

grunt-contrib-watch已经安装。

我会检查整个Gruntfile是否被包裹在里面。

module.exports = function (grunt) {

};

当您意外关闭此函数时,会出现所描述的错误。


0
当我在终端上运行grunt watch时,遇到了错误并进行了修复: 错误
grunt watch
Loading "Gruntfile.js" tasks...ERROR

终端中的 FIX

 brew install npm
 brew install node
  • 然后测试node和npm是否正常工作

    node -v
    npm -v
    
  • 安装Grunt

    npm install -g grunt-cli
    npm install grunt-contrib-watch --save-dev
    
  • 安装Composer

    curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
    
  • 然后运行

    grunt watch 
    

它运行成功了!


0
一个浏览器更新和npm更新对我有用。

0

实际上,如果插件未安装,则在运行grunt watch时不会出现错误,只会出现无法加载watch任务的错误。


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