【问题标题】:How to catch all errors from browserify?如何从 browserify 中捕获所有错误?
【发布时间】:2016-12-07 18:00:28
【问题描述】:

我使用以下 gulp 任务

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);

(一些正在进行的代码,我在函数调用中遗漏了一个参数)

我的问题是,我怎样才能更容易地听到这些错误?

我当然可以先对文件进行 lint,但我也想知道它是否可以在 browserify 中实现。

【问题讨论】:

    标签: javascript node.js gulp browserify watchify


    【解决方案1】:

    看起来 thiswatchify 的未合并拉取请求可能已经解决了您的问题 - 错误似乎没有在 gulp-watchify 模块中正确捕获,因此您永远无法看到它们。

    使用官方的 Gulp recipe 用于不使用 gulp-watchify 模块的 Browserify 和 Watchify 可能会更成功。


    问题似乎是 Gulp 在发生错误时从未被告知。尝试使用此错误处理代码:

    (error) => { 
        gutil.log('[error]', error); 
        this.emit('end');
    }
    

    【讨论】:

    • 对不起,我没有写那个,但我已经在使用那个食谱了。
    • 我对此进行了更多研究,并找到了另一个潜在的解决方案。检查我编辑的答案。
    猜你喜欢
    • 1970-01-01
    • 2011-11-15
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    • 2017-08-14
    • 1970-01-01
    • 2020-10-02
    相关资源
    最近更新 更多