Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JanPokorny opened this issue Jan 30, 2014 · 23 comments
Closed

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

JanPokorny opened this issue Jan 30, 2014 · 23 comments

Comments

@JanPokorny
Copy link

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.

@yocontra
Copy link
Member

Need: gulpfile, node -v, npm ls gulp

@yocontra
Copy link
Member

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

@JanPokorny
Copy link
Author

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.

@yocontra
Copy link
Member

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.

@JanPokorny
Copy link
Author

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

@yocontra
Copy link
Member

@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.

@JanPokorny
Copy link
Author

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:

node_modules
- 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.

@yocontra
Copy link
Member

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

** only matches directories

@JanPokorny
Copy link
Author

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.

@darsain
Copy link
Contributor

darsain commented Jan 31, 2014

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

@JanPokorny
Copy link
Author

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

@yocontra
Copy link
Member

Thanks @darsain

@shnigi
Copy link

shnigi commented Oct 10, 2016

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

@justindra
Copy link

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

@justindra
Copy link

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

@patricknelson
Copy link

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)

@jungleBadger
Copy link

Same issue happening here:

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

@jungleBadger
Copy link

jungleBadger commented Oct 22, 2017

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

@patricknelson
Copy link

Interestingly @jungleBadger I just noticed that the Windows built-in CLI (cmd.exe) worked fine for me regardless of the Quick Edit mode setting 🤔 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?

@jungleBadger
Copy link

@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.

@patricknelson
Copy link

🎉 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 browserify/watchify#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 👍

@jungleBadger
Copy link

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!!

@Manuel-Suarez-Abascal

This comment has been minimized.

@gulpjs gulpjs locked and limited conversation to collaborators Apr 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants