Gulp Watch only run once

I'm using this Gulp Watch sample:

var gulp = require('gulp');
var watch = require('gulp-watch');
var batch = require('gulp-batch');

gulp.task('build', function () { console.log('Working!'); });

gulp.task('watch', function () {
    watch('**/*.js', batch(function () {

When I run it on my Windows 8 machine, it only runs the first time I change a file:

C:\test>gulp watch
[08:40:21] Using gulpfile C:\test\gulpfile.js
[08:40:21] Starting 'watch'...
[08:40:21] Finished 'watch' after 2.69 ms
[08:40:31] Starting 'build'...
[08:40:31] Finished 'build' after 261 µs

Next time nothing happens. Why?

If you read the documentation closely, you see the following phrase:

You can pass plain callback, that will be called on every event or wrap it in gulp-batch to run it once

So, that's basically the deal with gulp-batch. To constantly watch it, just remove the batch call:

gulp.task('build', function (done) { 

gulp.task('watch', function () {
    watch('app/*.js', function () {

(and add the 'done' callback to build to let Gulp know when you're finished).

Btw... I'm not sure, but I think gulp-watch is meant to not only watch files, but also directly returning a vinyl object. So actually using the built-in should have the same effect:

gulp.task('watch', function () {'app/**/*.js', ['build']);

G4, The watch() API connects globs to tasks using a file system watcher. It watches If the task doesn't signal Async Completion, it will never be run a second time. This API Only one run can be queued up at a time. This is to avoid starting a task too early when many files are being changed at once - like find-and-replace. Dismiss Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

For me it was adding a "return" to the task:

gulp.task('styles', function(){
 return gulp.src('css/styles.css')

Watching Files, Gulp watch runs only once on the first change. I am running Wordpress on apache2 on ubuntu 14 and am using a tutorial. It illustrates how to use gulp to watch� Each watch() guarantees that its currently running task won't execute again concurrently. When a file change is made while a watcher task is running, another execution will queue up to run when the task finishes. Only one run can be queued up at a time. To disable queueing, set the queue option to false.

I had the same problem and used the same as ddprrt. The difference was using directory wildcard as apposed to absolute path.

I changed this:

 gulp.task('watch', function() {'sass/shortcutcss/*.scss', ['sass'])

to this:

 gulp.task('watch', function() {'sass/**/*.scss', ['sass'])

gulp-watch only runs once - node.js - html, gulp.task('watch', function () { watch('**/*.js', batch(function () { gulp.start('build'); })) ; }); When I run it on my Windows 8 machine, it only runs the first time I change� I have a gulpfile, it uses run sequence and When I make a change to a file, the watch task will run the task I specified exactly once. In this case, the task that should be executed is "run", which is the same as the default task except it doesn't run the dev server and watch task again.

Gulp Watch only run once - gulp - android, css files for example - or entire directories, or any combination you can think of. When Gulp Posted: Jul 20, 2015 If a function is provided, it will be called twice per path - once with just the path, then with the path and the fs.Stats object of that file. This option is passed directly to chokidar. followSymlinks: boolean: true: When true, changes to both symbolic links and the linked files trigger events. If false, only changes to the symbolic links

Gulp Watch Example, That's not going to work - Gulp needs to run automagically when a file changes. Well, there's magic to handle this called watch() , and for once, it comes native� The watch task is used to run tasks as we make changes to our files. As you write code and modify your files, the method will listen for changes and automatically run our tasks again so we don't have to continuously jump back to our command-line and run the gulp command each time. Default Task

Watch for Changes > Gulp! Refreshment for Your Frontend Assets , I am using Gulp with Elixir and coffee script but it only compiles what i make a change in the less files and I still get the same issue. gulp watch only runs once . #Quick Start. If you've previously installed gulp globally, run npm rm --global gulp before following these instructions. For more information, read this Sip. #Check for node, npm, and npx

gulp watch not watching js files ?, My gulp-watch task has been started normally, and the gulp command '\n Once git is installed, run \'' + gutil.colors.cyan('gulp install') + '\' again. So only the sass task was finished, and we cannot see the finish message of� flying-sheep changed the title Gulp 4: Watch only fires once Gulp 4: Watch only fires once when used with paths instead of globs Oct 11, 2015 phated added further investigation required gulp4 labels Oct 14, 2015

  • Did you change any file? Because you when you execute gulp watch, it is watching the files. When you then change a file, the function in watch gets fired.
  • Yes, maybe I'm not clear enough. I'm changing files, but watch is only executed the first time I change a file. E.g. if I start gulp watch, change something in my *.js file and save it, watch is running. If I then change something else in the same file and save it again, then watch is not running. The gulp watch process is still running, but nothing happens.
  • If you still want to use the gulp-batch the correct usage is to have a done callback there: done - is callback for your function signal to batch, that you are done. So: gulp.task('watch', function () { watch('**/*.js', batch(function (events, done) { gulp.start('build'); done(); })); });
  • Old post but lemme quote something again from what @ddprrt said, "(and add the 'done' callback to build to let Gulp know when you're finished)." And that nearly made me hit my head on the wall for hours. Thanks man
  • starting with gulp 4, the done callback is a must, it seems....thx!
  • ...or a passing and calling a callback: (cb) => { something(); cb(); }
  • Same problem and same solution here. Maybe open an issue on github about this would be a good ideia.
  • I had the same problem and resolved it adding the wildcard directory /**/*.scss, now it work
  • Looks like the issue is still relevant. /**/ wildcard dir resolved my issue.