Open benoitguigal opened 9 years ago
+1
Yeah, this is for real. Every time the plugin is called the addHooks
event listener is attached to Browserify. As you can see in this illustration
[ [Function: collect],
[Function: reset],
[Function],
[Function: addHooks],
[Function: addHooks],
[Function: addHooks],
[Function: addHooks],
[Function: addHooks],
[Function: addHooks],
[Function: addHooks],
[Function: addHooks],
[Function: addHooks],
[Function: addHooks],
[Function: addHooks] ]
Just add: bundler.on('reset', function () { gutil.log(bundler.listeners('reset')); });
, to see the results yourself. I'm guessing this probably leads to the excessive listeners on ConcatStream.
@benoitguigal to fix this do this to your rebundle
function:
var outputs;
bundler.plugin('factor-bundle', {
outputs: outputs
});
function rebundle() {
outputs = files.map(function (file) {
var name = path.basename(file, '.jsx');
return write("./" + name + '.js');
});
bundler.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(write('shared.js'));
}
And please give me that bounty on SO :smiley:
This seems like a real bug, looking into it. addHooks
should only be added once, you can see it's the saem logic as in watchify: https://github.com/substack/watchify/blob/e20c9a39fad48f411b2dc48a1d784a947bb8fb9e/index.js#L59-L60
So my SO solution doesn't work right. Luckily I have another solution in the interim until a PR is made.
So try this: Edit node_modules/factor-bundle/index.js
and change
From
b.on('reset', addHooks);
to
b.once('reset', addHooks);
Your original code should work.
Thanks Freyert, I will give it a try :-)
Cheeeers, has fixed for me
BTW @benoitguigal and @neilcarpenter nice sites/projects.
Haha thanks!! :) And yeah, ditto to @benoitguigal
+1, is there still no PR or merged code for this?
+1
this seems to be an issue still with 2.5.0
on Mac OSX
browserify ./client/src/app/*.js -p [ factor-bundle -o 'uglifyjs -cm > ./client/dist/js/`basename $FILE`' ] -o ./client/dist/js/common.js
the above "fix" does not solve the issue...
This was still a problem I had in my grunt karma task
Running "karma:ci" (karma) task
(node) warning: possible EventEmitter memory leak detected. 11 bundled listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at Browserify.addListener (events.js:179:15)
at Browserify.once (events.js:204:8)
at deferredBundle (/Users/user/Documents/feed/node_modules/karma-bro/lib/bro.js:183:11)
at Browserify.w.bundleFile (/Users/user/Documents/feed/node_modules/karma-bro/lib/bro.js:243:7)
at /Users/user/Documents/feed/node_modules/karma-bro/lib/bro.js:269:9
at nextPreprocessor (/Users/user/Documents/feed/node_modules/karma/lib/preprocessor.js:48:28)
at /Users/user/Documents/feed/node_modules/karma/lib/preprocessor.js:86:7
at evalmachine.<anonymous>:334:14
at /Users/user/Documents/feed/node_modules/karma/node_modules/graceful-fs/graceful-fs.js:102:5
at FSReqWrap.oncomplete (evalmachine.<anonymous>:95:15)
Injecting Rewireify into modules
I got it to stop by trying this line for an arbitrary number n
:
require('events').EventEmitter.prototype._maxListeners = n;
I continued to get warnings that I had n+1
bundled listeners until I finally set _maxlistners
to 103 or larger.
So if you're willing to sit down and find out how many listeners you've been adding, you can at least silence the warning by using the line above somewhere in the global scope.
I defined my browserify + watchify task exacly as here and got this problem as well.
(node) warning: possible EventEmitter memory leak detected. 11 reset listeners added. Use emitter.setMaxListeners() to increase limit.
Why this has not been fixed yet?
I used this ugly workaround, since I was not able to extract the plugin outside rebundle function
**
* fixes possible EventEmitter memory leak detected: https://github.com/substack/factor-bundle/issues/64
* @param {Browserify.BrowserifyObject} bundler
*/
function fixFactorBundleMemoryLeak(bundler) {
var listeners = bundler.listeners("reset").filter(l => l.name === "addHooks");
for (var i = 0; i < listeners.length - 1; i++) { //remove "reset" listeners except last
bundler.removeListener('reset', listeners[i]);
}
}
I am using factor-bundle with watchify and gulp.
It works fine but after five or ten rebundles I start seeing the following warning: