我正在使用gulp,browserify,watchify和factor bundle来开发几个javascript文件。一切正常,除了一段时间我开始看到这个警告:
Trace
at Browserify.addListener (events.js:179:15)
at f (/Users/benoit/git/figure/web/node_modules/factor-bundle/index.js:55:7)
at Browserify.plugin (/Users/benoit/git/figure/web/node_modules/browserify/index.js:345:9)
at Browserify.bundle (/Users/benoit/git/figure/web/gulpfile.js:46:13)
at Browserify.emit (events.js:107:17)
at null._onTimeout (/Users/benoit/git/figure/web/node_modules/watchify/index.js:126:15)
at Timer.listOnTimeout (timers.js:110:15)
(node) warning: possible EventEmitter memory leak detected. 11 finish listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at ConcatStream.addListener (events.js:179:15)
at ConcatStream.once (events.js:204:8)
at Labeled.Readable.pipe (/Users/benoit/git/figure/web/node_modules/factor-bundle/node_modules/labeled-stream-splicer/node_modules/stream-splicer/node_modules/readable-stream/lib/_stream_readable.js:612:8)
at /Users/benoit/git/figure/web/node_modules/factor-bundle/index.js:73:43
at Array.reduce (native)
at Transform._flush (/Users/benoit/git/figure/web/node_modules/factor-bundle/index.js:65:35)
at Transform.<anonymous> (/Users/benoit/git/figure/web/node_modules/factor-bundle/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:135:12)
at Transform.g (events.js:199:16)
at Transform.emit (events.js:129:20)
at finishMaybe (/Users/benoit/git/figure/web/node_modules/factor-bundle/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:371:12)
at endWritable (/Users/benoit/git/figure/web/node_modules/factor-bundle/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:378:3)
at Transform.Writable.end (/Users/benoit/git/figure/web/node_modules/factor-bundle/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:356:5)
(node) warning: possible EventEmitter memory leak detected. 11 finish listeners added. Use emitter.setMaxListeners() to increase limit.
以下是我的gulpfile
var gulp = require('gulp');
var gutil = require('gulp-util');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var reactify = require('reactify');
var watchify = require('watchify');
var factor = require('factor-bundle');
var uglify = require('gulp-uglify');
var fs = require('fs');
var concat = require('concat-stream');
var file = require('gulp-file');
gulp.task('watch', bundle)
function bundle () {
// react components
var files = [
'/path/to/file1.jsx',
'/path/to/file2.jsx',
'/path/to/file3.jsx'
];
var bundler = watchify(browserify(watchify.args))
bundler.add(files);
bundler.add('./lib/api.js', {expose: 'api'});
bundler.require('./lib/api.js', {expose: 'api'});
bundler.transform('reactify');
bundler.on('update', rebundle);
function rebundle() {
bundler.plugin('factor-bundle', {
outputs: [
write('/path/to/file1.js'),
write('/path/to/file2.js'),
write('/path/to/file3.js'),
]
});
bundler.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(write('shared.js'));
};
return rebundle();
}
function write (name) {
return concat(function (content) {
// create new vinyl file from content and use the basename of the
// filepath in scope as its basename.
return file(name, content, { src: true })
// uglify content
.pipe(uglify())
// write content to build directory
.pipe(gulp.dest('./public/bundles/'))
});
}
我读过我应该在某处设置最大侦听器,但恐怕这可能是一个天才内存泄漏。
答案 0 :(得分:1)
我的初始解决方案不起作用,看起来它确实是一个错误。我想我已经找到了一个临时的hacky修复。
修改node_modules/factor-bundle/index.js
并更改
从
b.on('reset', addHooks);
至
b.once('reset', addHooks);
您的原始代码应该有效。
以下是GitHub issue以及任何保持得分的人:D