Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watchify update event never fires in Virtualbox

I am trying to get watchify working with Gulp but it seems that the 'update' event is never fired.

Here's my gulpfile.js:

"use strict";

var gulp = require('gulp');
var browserify = require('browserify');
var source = require("vinyl-source-stream");
var watchify = require('watchify');

var bundler = watchify(browserify({entries: ['./client/app/app.js'], cache: {}, packageCache: {}, fullPaths: true}));

gulp.task('js', bundle); 

function bundle() {
    console.log('bundle');
    return bundler.bundle()
    .pipe(source('bundle.js'))
    .pipe(gulp.dest('./dist'));
}

// this is never fired!
bundler.on('update', bundle);

However, when I explicitly watch the files without watchify it works:

"use strict";

var gulp = require('gulp');
var browserify = require('browserify');
var source = require("vinyl-source-stream");
var watchify = require('watchify');

function bundle() {
    console.log('bundle');
    return browserify('./client/app/app.js')
    .bundle()
    .pipe(source('bundle.js'))
    .pipe(gulp.dest('./dist/'));
}

gulp.task('browserify', bundle);

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

I've tried numerous examples but with watchify the bundle never updates.

I'm running Gulp inside a Vagrant VM, host is OSX Yosemite, guest is Ubuntu 14.04.

Any help is greatly appreciated!

like image 557
Danny Moerkerke Avatar asked Dec 23 '14 11:12

Danny Moerkerke


2 Answers

Polling was added in 3.0.0.

You can activate it with the poll option.

var w = watchify(b, {
  poll: true
});

From docs: opts.poll enables polling to monitor for changes. If set to true, then a polling interval of 100ms is used. If set to a number, then that amount of milliseconds will be the polling interval. For more info see Chokidar's documentation on "usePolling" and "interval". This option is useful if you're watching an NFS volume.

like image 186
Matt Rose Avatar answered Sep 30 '22 17:09

Matt Rose


This is because watchify relies on inotify to detect file changes which works great as long as they are initiated from inside your virtual machine (e.g. using touch on these files). However, it won't pick up changes performed outside because of a limitation with VirtualBox that doesn't trigger appropriate events in the guest system when a file is changed in the host system. Apparently VMware suffers from the same problem.

There are currently some discussions to fall back to polling for network mounts in watchify and chokidar (which watchify actually uses to watch files) to alleviate this particular problem:

  • https://github.com/substack/watchify/issues/120
  • https://github.com/paulmillr/chokidar/issues/242
like image 43
Stéphane Avatar answered Sep 30 '22 17:09

Stéphane