Javascript 如何从browserify捕获所有错误?
我使用以下吞咽任务Javascript 如何从browserify捕获所有错误?,javascript,node.js,gulp,browserify,watchify,Javascript,Node.js,Gulp,Browserify,Watchify,我使用以下吞咽任务 const gulp = require('gulp'); const browserify = require('browserify'); const watchify = require('watchify'); const source = require('vinyl-source-stream'); const gutil = require('gulp-util'); gulp.task('wat
const gulp = require('gulp');
const browserify = require('browserify');
const watchify = require('watchify');
const source = require('vinyl-source-stream');
const gutil = require('gulp-util');
gulp.task('watchify', () => {
var bundler = watchify(browserify('./test/app.js', {
debug: true,
fullPaths: true,
paths: ['./src'],
cache: {},
packageCache: {}
}))
.on('update', bundle)
.on('error', (error) => { gutil.log('[error]', error); });
function bundle(){
return bundler
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('./test/'));
}
return bundle();
});
但今天browserify进程挂起,没有发送错误事件,经过数小时的跟踪和错误后,我发现这是由于以下原因:
aFunction(argA, , argC);
(一些正在进行的代码,其中我在函数调用中错过了一个参数)
我的问题是,我怎样才能更容易地听到此类错误?
当然,我可以先删除文件,但我也想知道是否可以在browserify中执行此操作。对于watchify
的未合并拉取请求可能已经解决了您的问题-错误似乎无法在gulp watchify
模块中正确捕获,因此您永远无法看到它们
使用官方的Browserify和Watchify可能会更成功,因为它不使用gulpWatchify
模块
问题似乎是Gulp在发生错误时从未被告知错误。请尝试使用以下错误处理代码:
(error) => {
gutil.log('[error]', error);
this.emit('end');
}
对不起,我没有写那个,但我已经在用那个配方了。我对它做了更多的研究,并找到了另一个可能的解决方案。检查我编辑的答案。