1

I have a React app created bu CRA and it is ejected. When I am trying to build the app using npm run build (node scripts/build.js), I get a warning:

(node:6) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added. Use emitter.setMaxListeners() to increase limit.

How important is this warning and I how can I fix this issue?

Hadi Ranjbar
  • 1,692
  • 4
  • 21
  • 44

2 Answers2

1

You can increase the limit using emitter.setMaxListeners(n) A better approach is using React's life cycle hook's and unsubscribe from the listeners.

Tom Shaw
  • 1,642
  • 2
  • 16
  • 25
1

How important is this warning and I how can I fix this issue?

It depends upon what your code is doing.

If you just have more than 10 legitimate listeners to some EventEmitter object and all the listeners are legit, then the warning can be ignored or you can use emitter.setMaxListeners() to set it to a much higher warning value.

On the other hand (and the reason the warning is here), if you didn't mean to have more than 10 listeners and the only reason it got to more than 10 is because you failed to remove some old listeners that are no longer being needed, then it is a sign of a problem and you need to find where those listeners are added and then find where you can safely remove each one when you are done with it.

Here's an example of a case from another question today where the listener did need to be removed. You can see that example here:

Node.JS Server Sent Events: Route continues to run after res.end() resulting in ERR_STREAM_WRITE_AFTER_END error

If you showed us your actual code that adds the listeners and the context around it, we may be able to advise you more specifically on whether you should be removing the listener or not.

jfriend00
  • 683,504
  • 96
  • 985
  • 979