6

I'm having trouble configuring Grunt to watch my project files, rebuild and update a page hosted in a connect server. If I run any of the build tasks and then 'watch' as part of a combined task, then 'watch' seems to get stuck in a loop, endlessly printing the message.

Running "watch" task
Waiting...
Warning: must provide pattern

If instead I just run $ grunt watch, it will happily watch my source files and compile/build as appropriate.

I think the relevant task configurations are these:

watch: {
  html: {
    files: [ '<%= site.partials %>', '<%= site.layouts %>', '<%= site.pages %>' ],
    tasks: [ 'html' ]
  },
  sass: {
    files: [ '<%= site.src %>sass/*.scss' ],
    tasks: [ 'styles' ]
  }
},

// development server
connect: {
  options: {
    port: 8080,
    livereload: 35729,
    hostname: 'localhost',
  },
  dev: {
    options: {
      directory: 'build',
    }
  }
},

and the task definitions:

grunt.registerTask( 'build', [ 'styles', 'html', ] );
grunt.registerTask( 'default', [  'build','connect:dev', 'watch' ] );

The 'styles' and 'html' tasks run grunt-sass and assemble. As stated above, running any of these tasks, or even 'watch' on its own yields the expected results. This suggests my config object has site.partials, site.dest etc defined correctly. The problem only happens when I run any task and then 'watch', as in the default task.

Simon Dell
  • 638
  • 1
  • 7
  • 17
  • I suspect the problem is in the templates referencing the `site` object. However, without seeing that part of your `grunt.initConfig` call, I really can't say. I know this question is old now, but can you either post your entire Gruntfile or, if you've solved the problem, post your answer? – matty Jul 01 '15 at 12:14

2 Answers2

17

I just encountered a similar problem when I had been editing my Gruntfile and left a field (that should have had a file pattern) blank.

Check your Gruntfile for an empty file field.

In my specific example:

wiredep: {
    options: {
        overrides: {
          "jquery-ui": {
              "main": [
                 "jquery-ui.js",
                 "themes/base/jquery-ui.css",
                 ""
              ]
          }
        }
    }
}

Note the empty string above. That generated an error very similar to yours. It seems that Grunt doesn't tell you where the error is, unfortunately. You'll just need to scan through your Gruntfile manually to find the error.

Sam Jacobson
  • 431
  • 5
  • 7
  • Grunt really is useless at letting you know where the error is, took me ages to track it down, but it was exactly this. – Mike Mellor Dec 08 '16 at 16:28
  • 1
    In this context a string like `"<%= cfg.foo %>"` is also empty when there is no `foo` in `cfg`. This is the problem I had. – JonnyJD Jan 06 '17 at 14:45
-1

connect:dev is the problem. Remove that and it should work fine.

Jean
  • 670
  • 1
  • 5
  • 14
  • `grunt-contrib-connect` is a multi-task and should be able to handle multiple targets simultaneously. Their documentation even suggests numerous examples like this. Why would a simple target with one option (an option connect needs) cause a problem? – Simon Dell Nov 11 '14 at 23:35
  • Without further explanation, this comment is random, maybe created by a Jean-bot. The purpose of answering is to inform both the original poster and other readers. Why is `connect:dev` a problem? I suspect it is not. – matty Jul 01 '15 at 12:12