I have setup a node.js gulp file to use the babel transform allowing me to utilize ES6 features in browser scripts.
When I add an intentional syntax error to the input file I am not seeing any error messages being output by babelify despite having subscribed to the 'error' event as suggested in the Using Babel with Browserify guide.
Example of invalid syntax:
immmmport $ from 'jquery';
Instead of showing an error in the CLI it just silently fails.
Here is how I have configured my gulp task:
gulp.task('build', () => {
browserify(options)
.transform(babelify)
.add(sourceFilePath)
.bundle()
.pipe(source(outputFileName))
.pipe(buffer())
.pipe(gulpif(!argv.production, sourcemaps.init({ loadMaps: true })))
.pipe(gulpif(argv.production, streamify(uglify())))
.pipe(gulpif(!argv.production, sourcemaps.write('/')))
.pipe(gulp.dest(outputDirName));
})
Am I missing any steps here?
The source of this problem was that I needed to add the following line:
.on("error", err => { gutil.log("Browserify Error", gutil.colors.red(err.message)) })
So that I have this:
gulp.task('build', () => {
browserify(options)
.transform(babelify)
.add(sourceFilePath)
.bundle()
.on("error", err => { gutil.log("Browserify Error", gutil.colors.red(err.message)) })
.pipe(source(outputFileName))
.pipe(buffer())
.pipe(gulpif(!argv.production, sourcemaps.init({ loadMaps: true })))
.pipe(gulpif(argv.production, streamify(uglify())))
.pipe(gulpif(!argv.production, sourcemaps.write('/')))
.pipe(gulp.dest(outputDirName));
})
The following page was useful in diagnosing this issue: