Next.js Discord

Discord Forum

How to debug "Watchpack Error (watcher): Error: EMFILE: too many open files, watch"?

Unanswered
Kaikadi posted this in #help-forum
Open in Discord
KaikadiOP
Hi there! I am really struggling to debug a development error I just started receiving:

Watchpack Error (watcher): Error: EMFILE: too many open files, watch

Randomly while running next dev my terminal will display the error above. From what I've seen normally, the watch keyword is followed by the path that Watchpack is erroring out at but in my case it's just empty.

Does anyone know how to debug this error so I can find the culprit? I have a monorepo with 6 internal packages so I'm assuming that Watchpack is somehow watching the node_modules of the shared libraries to cause this problem. But I can't know for sure unless I can see what files Watchpack is actually...watching, you know?

Also, I understand that some 3rd party packages like lucide-react need some help to reduce imports via modularizeImports but the NextJS team already does this for lucide-react and some other libraries automatically. Is it possible to like, see what packages may need to be modularized to reduce import size (if that's even the issue?)

My dev server is also compiling 6000+ modules and I would like to figure out where all those are coming from. This is a big project so I'd expect a lot of modules but maybe this seems out of the ordinary too?

Compiled /app in 10.6s (6256 modules)

Does anyone have any guidance or has run in to and solved this before? Thanks a lot!

NextJS: 14.2.4
NodeJS: v20.12.0

9 Replies

also whats your package.json
KaikadiOP
@!=tgt Deleting my .next does help but only for a short period of time and then the issue returns. Here are my dependencies
that is a LOT of dependencies
can you try next dev --turbo
KaikadiOP
@!=tgt haha i mean not really, it's a 6 year old project in heavy development, plus a lot of those are from the same projects that just split their deps across different modules lol (ie tiptap/trpc/tanstack/capacitor/uppy)

turbo unfortunately doesnt work because it fails when using ffmpeg so I can't use it (yet)
Palomino
did you find a solution for this?
it's happening to me too
huge blocker