gulp.watch(...) not working on Windows

Created on 30 Jan 2014  路  23Comments  路  Source: gulpjs/gulp

gulp.watch doesn't seem to work for me, and I think it's a Windows-related issue. If I use the example gulpfile.js from the readme, create the directory structure (client/js, client/img, build/js, build/img), and a dummy js file in the client/js folder, the gulp scripts task runs normally and minifies the script, but gulp watch fails to update the minified file when the original changes.
The console output:

>gulp watch
[gulp] Using file C:\Users\JP\Documents\gulptest\gulpfile.js
[gulp] Working directory changed to C:\Users\JP\Documents\gulptest
[gulp] Running 'watch'...
[gulp] Finished 'watch' in 17 ms

There is no prompt afterwards, it continues "running", but it doesn't do anything.

Most helpful comment

I have this exactly same problem. Running
$ gulp -v
[12:10:36] CLI version 3.9.1

All 23 comments

Need: gulpfile, node -v, npm ls gulp

Also this is probably a gaze problem, gulp doesn't actually have any file watching logic in it.

gulpfile: exactly the same one as in README.md
node version: 0.10.25
gulp version: 3.4.0

I tried using gulp-watch module, and it works. gulp-watch uses gaze too.

This is expected behavior - what's the problem? The task just sets up watchers and ends. The node process will continue running (it's watching the files). When you modify files being watched then whatever handler was set up will be called.

No, there is a problem. The watching doesn't work: it doesn't run the task when some of the files change.

@JohnnyPopcorn When you open an issue you need to provide as much information as possible. "Doesn't work" is usually going to get your issue closed quickly. I need the full path of the file you're modifying, your working directory where you are running the gulp process, location of your gulpfile, etc.

OK, I'll try again with simplified gulpfile and directory structure.

node version: 0.10.25
gulp version: 3.4.0
OS: Windows 7 64bit

My directory structure:

- gulp
- gulp-uglify
build
- test.js   //minified file
client
- test.js   //original file
gulpfile.js

gulpfile.js contents:

var gulp = require('gulp');
var uglify = require('gulp-uglify');

gulp.task('scripts', function() {
  return gulp.src('client/**/*.js')
    .pipe(uglify())
    .pipe(gulp.dest('build/'));
});

gulp.task('watch', function () {
  gulp.watch('client/**', ['scripts']);
});

client/test.js contents:

function something()
{
    var longName = 42;
    alert(longName);
}

build/test.js contents (generated by gulp scripts):

function something(){var n=42;alert(n)}

Steps to reproduce:
Run gulp watch in the project folder.
Change 42 in client/test.js to 43 and save the file.

Expected behavior:
The build/test.js should update to contain:

function something(){var n=43;alert(n)}

Actual behavior:
The build/test.js didn't change and still contains

function something(){var n=42;alert(n)}

This probably isn't gaze issue, because third-party gulp-watch npm module uses gaze too, but works for me.

Try gulp.watch('client/**/*.js', ['scripts']); instead of gulp.watch('client/**', ['scripts']);

** only matches directories

Sorry, I made that mistake when simplifying the gulpfile. New gulpfile:

var gulp = require('gulp');
var uglify = require('gulp-uglify');

gulp.task('scripts', function() {
  return gulp.src('client/**/*.js')
    .pipe(uglify())
    .pipe(gulp.dest('build/'));
});

gulp.task('watch', function () {
  gulp.watch('client/**/*.js', ['scripts']);
});

Issue still persists.

You are using gulp 3.4.0 that doesn't support this .watch() signature IIRC. Update to 3.5.0.

Updated to 3.5.0 and it works, thanks. I have no idea why npm installed the older version for me.

Thanks @darsain

I have this exactly same problem. Running
$ gulp -v
[12:10:36] CLI version 3.9.1

I have a similar problem too
node v7.2.1
gulp v3.9.1
Windows 10 64-bit

I downgraded to node 6.9.2 and that seems to have fixed the problem.

Looks like this is the issue that some google search results will lead to (how I got here). For reference, and if you still can't reopen the issue, could we get a link to the currently open issue that does regard this, if any exists? Still a problem. Similar specs as @justindra

node v6.9.1
gulp: CLI v1.2.2
gulp: Local v3.9.1
Windows 10 (x64)

Same issue happening here:

node v6.11.4
gulp -g: 3.4.1
Windows 10 (x64)

Hey guys I find a possible solution to us:

Within your CMD settings uncheck the "Quick Edit mode" box and watch/batch processes should work properly.

OBS: Portuguese version of settings.

Right click on the CMD tab and select Properties/Settings option
image

Uncheck the "Quick edit mode" box
image

Interestingly @jungleBadger I just noticed that the Windows built-in CLI (cmd.exe) worked fine for me regardless of the Quick Edit mode setting :thinking: Then it stopped working again.

I've normally been having this problem consistently when utilizing Jet Brain's (or specifically: PhpStorm) integrated terminal window. Maybe this is some kind of race condition where gulp skips a few cycles and misses the change hooks/notifications coming in from the file system due to slowdowns or some kind of interference in the terminal window (e.g. cmd.exe or otherwise) executing gulp?

@patricknelson it does happen to me in any cmd (git bash, cmd, powershell) that I use.

And in fact I do use jetbrains (webstorm) IDE.

馃帀 Alright, I've fixed my issue.

Turns out it wasn't related to gulp.watch(...), I was using watchify this entire time (oops 馃). That said, @jungleBadger I think we might have the same problem (judging from your screenshot which revealed you may be using browserify/watchify as well). I believe the issue we were having may be related to https://github.com/browserify/watchify/issues/312.

I fixed my issue by converting my code to gulp-bro which has a much simpler syntax and works like a regular gulp plugin. That way I simply use the native gulp.watch(...) API to watch for changes and trigger rebuilds 馃憤

hey @patricknelson I will change it and give it a try.

Without the "edit mode" option my browserify/watchify routine ran much better and consistent but it stills does not recognize properly sometimes, and to bypass those situations I need go to code and put a new line anywhere then the build is triggered just fine.

I will give a try to gulp-bro later and let you know if it worked (working on macbook right now).

Thanks!!

Gulp.watch() isn't working for me either. I am using Git Bash & Window 10 (64-bits).

Another related info:
Node v10.15.3
NPM 6.4.1
Gulpjs 3.9.1

Does anybody knows if this issue was resolved or there is any workaround? Thanks in advance!

Was this page helpful?
0 / 5 - 0 ratings