MaxListenersExceededWarning: Possible EventEmitter memory leak..
I recently switched my project from CJS to ESM, and while nothing in my code actually changed other than my import/export syntax, I am now getting the following alert which never happened in the years of running the bot before the changes
I have added
setMaxListeners(20)
to suppress the alert in the mean time, which it has, but I'm curious to know where this has come from and if I need to look into it more? I do have about 16 client event listeners, and I only use the intents/partials that I require7 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ✅
Marked as resolved by OP11 undefined listeners added to [Client]I imagine you're using the
Events
enum and didn't properly migrate how it was imported to esmSo when I log
client._events
I get the following output. These appear to be all the events that I am listening to, but still getting that same warning
in case it wasn't clear, the relevant information was that it says 11 undefined listeners
which is to say, it believes the event name is
undefined
as a rule of thumb I tend to not rely on private properties, but putting that aside, I do see that this output does not have undefined
listed, so it sounds like the undefined
listeners are being added after this
but regardless it'll be hard to help further without seeing any codeRoger that, I did double check if the event name values were correct, and they were. Here is my event handler
Here is a snippet of how I'm applying those name values
As far as I can tell, everything is imported and exported as expected, but I very well might be missing something
Excuse the ping, force of habit hitting reply
Also those are the only listeners I'm using, so I'd be confused how any more are being added after the fact
If you need anything else, let me know
personally I don't mind being pinged if I'm already relevant to a conversation
there doesn't appear to be anything overtly wrong with just this code you've shown
I suppose you could use the
--trace-warnings
flag to confirm where the given undefined
listener is being added (as your warning probably mentioned)For sure, I'll give it a try and see what I can find.
Might also be worth mentioning that the warning will randomly show up. I'd expect it to show up around the time I run the bot, seeing as that is when I'm importing those events, but it's usually within 10-30 minutes after.
I have doubled checked to see if I might just randomly be registering a listener somewhere throughout my code, but I can't find anything
Appreciate the help, will update if I find anything
Well I've been running it with the trace warnings flag for about an hour now with no max listener warning, so I'm going to assume something I've done fixed it 🤷🏽♂️