sparebytes sparebytes - 4 months ago 21
Node.js Question

Make node show stack trace after EventEmitter warning

I have this error:

(node:11164) Warning: Possible EventEmitter memory leak detected. 11 end listeners added. Use emitter.setMaxListeners() to increase limit


No stack trace is given so I have no idea which event might be the culprit.

I tried to work around it by overriding
console.warn
but the stack trace at that point is of no use since
console.warn
is not called when the listener is added but some arbitrary time afterwards.

Answer

This changed with Node v6 (or possibly with v5).

Previously, a stack trace was shown automatically, now you have to generate one yourself:

process.on('warning', e => console.warn(e.stack));

Documented here.

Comments