簡體   English   中英

如何從browserify中捕獲所有錯誤?

[英]How to catch all errors from browserify?

我使用以下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();

});

但今天瀏覽器進程掛起而沒有發送錯誤事件,經過數小時的跟蹤和錯誤我發現它是因為這樣的事情:

aFunction(argA, , argC);

(一些正在進行中的代碼,我錯過了函數調用中的參數)

我的問題是,我怎樣才能更容易地聽到這類錯誤?

我當然可以先把文件弄臟,但我也想知道它是否可以在browserify中使用。

看起來這種watchify合並拉取請求可能已經修復了你的問題 - 看起來錯誤沒有在gulp-watchify模塊中被正確捕獲,所以你永遠不會看到它們。

使用Browserify和Watchify的官方Gulp配方可能會更成功,它不使用gulp-watchify模塊。


似乎問題是Gulp在發生錯誤時從未被告知。 嘗試使用此錯誤處理代碼:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM