nextjs - 💡(How to fix) Fix Turbopack dev on macOS hits Watchpack fs.watch EMFILE on ancestor directories and app subtrees [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#93173Fetched 2026-04-24 10:35:43
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
closed ×1commented ×1labeled ×1locked ×1

On macOS, Next.js 16.2.3 Turbopack development mode is hitting repeated native fs.watch EMFILE errors even with a very high shell file-descriptor limit. The failure appears in Watchpack, triggers false next.config.js restarts, and can destabilize the dev server.

Error Message

[fs.watch EMFILE event] /private [fs.watch EMFILE event] /private/tmp [fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro [fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app [fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app/about [fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app/api [fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app/internal [fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app/states Watchpack Error (watcher): Error: EMFILE: too many open files, watch ⚠ Found a change in next.config.js. Restarting the server to apply the changes...

Root Cause

  • next dev with Turbopack should watch only the needed project paths without entering an EMFILE loop
  • A high ulimit -n should not still result in repeated native watcher failures
  • Turbopack should not restart because of false-positive config change detection during watcher failure

Code Example

[fs.watch EMFILE event] /private
[fs.watch EMFILE event] /private/tmp
[fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro
[fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app
[fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app/about
[fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app/api
[fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app/internal
[fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app/states
Watchpack Error (watcher): Error: EMFILE: too many open files, watch
Found a change in next.config.js. Restarting the server to apply the changes...
RAW_BUFFERClick to expand / collapse

Title: Turbopack dev on macOS hits Watchpack fs.watch EMFILE on ancestor directories and app subtrees

Summary

On macOS, Next.js 16.2.3 Turbopack development mode is hitting repeated native fs.watch EMFILE errors even with a very high shell file-descriptor limit. The failure appears in Watchpack, triggers false next.config.js restarts, and can destabilize the dev server.

Version

Next.js 16.2.3

Link to the code that reproduces this issue

https://github.com/wzrdgang/next-turbopack-emfile-macos-repro

To Reproduce

  1. On macOS, clone the repro repo.
  2. Run npm install
  3. Run npm run dev:debug
  4. Observe repeated Watchpack Error (watcher): Error: EMFILE: too many open files, watch
  5. Observe the debug watcher targets printed by the fs.watch preload in scripts/watch-debug.cjs

Current vs. Expected behavior

Current behavior:

  • Turbopack dev starts, then immediately emits repeated Watchpack EMFILE errors
  • The debug logger shows fs.watch EMFILE events for ancestor directories like:
    • /Users
    • /Users/<user>
    • /Users/<user>/Documents/...
    • the project root
    • multiple app/... subdirectories
  • The same run also triggers false Found a change in next.config.js. Restarting the server to apply the changes...

Expected behavior:

  • next dev with Turbopack should watch only the needed project paths without entering an EMFILE loop
  • A high ulimit -n should not still result in repeated native watcher failures
  • Turbopack should not restart because of false-positive config change detection during watcher failure

Environment

  • OS: macOS 15.7.4
  • Kernel: Darwin 24.6.0 arm64
  • Node versions tested:
    • 25.9.0
    • 24.14.0
  • npm: 11.12.1
  • ulimit -n: 1048575

Additional context

  • The repro intentionally creates a moderately wide App Router tree under app/ because the larger real-world app showed the same failure pattern
  • The failure reproduced with both Node 25.9.0 and Node 24.14.0
  • The repro still succeeds with npm run build, so the problem appears isolated to Turbopack dev watchers
  • A validated watcher-target excerpt is included in VALIDATED_WATCH_LOG.txt
  • In the larger Munimetric app, the same logger also showed native watch attempts on /Users, /Users/samhowell, /Users/samhowell/Documents, /Users/samhowell/Documents/munimetric, /Users/samhowell/Documents/munimetric/frontend, /Users/samhowell/Documents/munimetric/frontend/app, and many frontend/app/... route directories
  • In the larger app, webpack + polling works around the issue, but that bypasses Turbopack instead of fixing it

Validated watcher-target excerpt

[fs.watch EMFILE event] /private
[fs.watch EMFILE event] /private/tmp
[fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro
[fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app
[fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app/about
[fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app/api
[fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app/internal
[fs.watch EMFILE event] /private/tmp/next-turbopack-emfile-macos-repro/app/states
Watchpack Error (watcher): Error: EMFILE: too many open files, watch
⚠ Found a change in next.config.js. Restarting the server to apply the changes...

extent analysis

TL;DR

The issue can be mitigated by adjusting the watch configuration to exclude unnecessary directories and increasing the file descriptor limit.

Guidance

  • Review the next.config.js file to ensure that only necessary directories are being watched by Turbopack.
  • Increase the file descriptor limit using ulimit -n to a higher value, if possible, to reduce the likelihood of EMFILE errors.
  • Consider using a polling-based approach as a temporary workaround, similar to the larger Munimetric app.
  • Investigate the Watchpack configuration to determine if there are any options to exclude ancestor directories from being watched.

Example

No code snippet is provided as the issue is more related to configuration and environment settings.

Notes

The issue appears to be specific to macOS and Turbopack development mode, and may be related to the way Watchpack handles file system events. Increasing the file descriptor limit and adjusting the watch configuration may help mitigate the issue, but a more permanent fix may require changes to Watchpack or Turbopack.

Recommendation

Apply a workaround by adjusting the watch configuration and increasing the file descriptor limit, as a permanent fix may require changes to the underlying libraries.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix Turbopack dev on macOS hits Watchpack fs.watch EMFILE on ancestor directories and app subtrees [1 comments, 2 participants]