Catching Browserify parse error (standalone option)
The on('error')
event is still fired. However, browserify stream is a bit different from other Gulp stream. In the error handler function of browserify, you need to explicitly call this.emit("end")
An example gulp task
var browserify = require('browserify');
var gulp = require('gulp');
var source = require("vinyl-source-stream");
var reactify = require('reactify');
gulp.task('browserify', function(){
// create new bundle
var b = browserify();
// add transform if you want
b.transform(reactify);
// add file to browserify
b.add("./src/main.js");
// start bundling
return b.bundle()
.on('error', function(err){
// print the error (can replace with gulp-util)
console.log(err.message);
// end this stream
this.emit('end');
})
.pipe(source('main.js'))
// pipe other plugin here if you want
.pipe(gulp.dest('./dist'));
});
the error function handler prevents gulp from crashing, this.emit("end")
stops the current stream, not let it run to the next pipes. The event handler can also catch error in the transform plugin.
For more information, you can read here http://truongtx.me/2014/07/15/handle-errors-while-using-gulp-watch/
JavaScript - Gulp/Browserify: SyntaxError: Unexpected token
Wait... this is not valid javascript:
module.exports = {
console.log('Hello World');
};
Maybe you meant this?
module.exports = function () {
console.log('Hello World');
};
Whats the difference between Gulp-Browserify and Browserify?
The difference is that browserify doesn't natively read and emit the vinyl files that the gulp pipeline deals with. gulp-browserify was an adapter for that, and I believe it did some extra things related to error handling. If possible I recommend that for the time being you avoid using gulp-browserify. In gulp 4 there may be a better way to integrate browserify with gulp. For now, see if this works for you:
var vss = require('vinyl-source-stream');
gulp.task('whatever', function () {
var b = browserify(entry, b_opts)
.transform(some_xform);
return b.bundle()
.pipe(vss('bundle.js'))
// ... gulp stuff
.pipe(gulp.dest(dest));
});
This will generally require you to do per-file manipulations with browserify transforms and then only do bundle-level manipulation in the gulp pipeline.
Further reading: gulpjs/gulp#369
Related Topics
Is There Any Difference Between '=' and '==' Operators in Bash or Sh
"Unknown Symbol in Module" on Module Insertion Despite Export_Symbol
How Does Iwlist() Command Scans The Wireless Networks
Avoid Copying of Data Between User and Kernel Space and Vice-Versa
Reliable Bidirectional Communication to a Linux Process
Bash Script with User Defined Functions in Autocomplete
Change Directory Using Loop in Linux
How to Get The Interrupt Vector Number on Linux
When to Use Linux Kernel Add_Timer Vs Queue_Delayed_Work
Is There Any General Interfaces on Linux to Simulate Mouse Movements and Click
Interpreting Openssl Speed Output for Rsa with Multi Option
Accessing Apache2 Residing Inside Docker Container from Host Machine Web Browser
Can Not Add New User in Docker Container with Mounted /Etc/Passwd and /Etc/Shadow
Sysfs Interface. I Can't Export Gpio Pins in a Xilinx's Board (Zybo and Other)