0

Here is a very minimalistic example gulpfile.js:

var gulp = require('gulp');
function foo(done) {
    console.log('change');
    done();
}
function watchFiles() {
    console.log('starting watching...');
    gulp.watch('./gulpfile.js', gulp.series(foo));
};
gulp.task('watch-files', gulp.series(watchFiles));

A message "change" should be displayed on the console every time, when the gulpfile.js itself gets edited. But it doesn't work. I get the initial message "starting watching..." and the Gulp info about starting the task displayed.

$ gulp watch-files
[[[00:07:48] Using gulpfile /var/www/.../my-app/gulpfile.js
[00:07:48] Starting 'watch-files'...
[00:07:48] Starting 'watchFiles'...
starting watching...

But changes on the defined file to be observed (the gulpfile.js) are ignored, so no further messages are being displayed.

What causes the issue and how to fix it and get the watching working?

automatix
  • 14,018
  • 26
  • 105
  • 230
  • 1
    I pasted your code into a test and it worked. This helped, otherwise it only runs once: `function foo(done) { console.log('change'); done(); }` I just added the `done`s so it terminates the `foo` task. – Mark Aug 20 '19 at 22:46
  • Thanks for the comment! Are you getting the output "change" every time, when you edit&save the `gulpfile.js`? – automatix Aug 21 '19 at 10:07
  • Yes. it works as you expected. – Mark Aug 21 '19 at 14:05
  • I updated to code with `done`, so that it runs not only once, but on every change. So thanks again for your first comment. After it I tried running `gulp watch-files` in the same folder (meaning: with the same `gulpfile.js`) on my Windows 7 host system. There it's working. But it's still not working on my Ubuntu VirtualBox VM. So the environment seems to make the difference. – automatix Aug 21 '19 at 15:26

0 Answers0