Description
If browserify
is given the watchify
plugin, it will silently freeze if there's an import of a non-existent module anywhere in the source files reachable via entries
.
I've isolated a minimal complete reproducible example:
src.js:
import foobar from 'someNonExistantPackage';
gulpfile.js:
const gulp = require('gulp');
const watchify = require('watchify');
const browserify = require('browserify');
const vinylSource = require('vinyl-source-stream');
const vinylBuffer = require('vinyl-buffer');
function createBundler() {
return browserify({
entries: ['./src.js'],
}).plugin(watchify);
}
function bundle(bundler) {
return bundler.bundle()
.pipe(vinylSource('dst.js'))
.pipe(vinylBuffer())
.pipe(gulp.dest('./'))
.on('error', console.error)
.on('end', () => { console.log('Done'); });
}
gulp.task('default', () => {
return bundle(createBundler());
});
What I expect to happen is for an error to be thrown. I should see it either in .on('error', console.error)
or by the gulp task crashing. What happens in practice is that the task freezes without printing anything.
If the watchify
plugin is removed from the chain, then the task continues and errors successfully:
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
which is expected, because I removed the babel transform from the example to keep it minimal. If babel is added, then dst.js
is successfully generated as long as watchify
is not used.
This happens to me on:
- browserify version 16.5.0
- watchify version 3.11.1