Skip to content

EMFILE error during development due to chokidar #2067

@mengxi-ream

Description

@mengxi-ream

Describe the bug

During development, after running for a while or after multiple file changes, Node crashes with:

const error = new UVException({
                    ^

Error: EMFILE: too many open files, watch

This appears to be related to chokidar (version 4.0.3) which WXT uses for file watching. The error occurs even though:

  • System ulimit -n is set to 65536
  • Actual open file count is very low (~113 files across all vite processes)

This suggests it's not a real file descriptor exhaustion but a bug in chokidar itself, as reported in paulmillr/chokidar#1385

Root Cause Analysis

WXT depends on chokidar 4.0.3 through multiple paths:

  • Direct dependency of wxt
  • Via c12 (wxt's sub-dependency)
  • Via @wxt-dev/i18n

Chokidar 4.x appears to have race condition issues that cause false EMFILE errors even when file descriptors are not actually exhausted.

Note: Vite itself no longer uses chokidar (switched to native fs.watch or @parcel/watcher in Vite 5+), so this issue is specific to WXT's own file watching.

Question for Maintainers

Would it be possible to switch WXT's file watcher away from chokidar to something more stable like @parcel/watcher or native fs.watch? This would align with what Vite itself has done and potentially avoid these reliability issues.

Reproduction

Using Read Frog (open source browser extension):

git clone https://github.com/mengxi-ream/read-frog.git
cd read-frog
pnpm install
pnpm dev

Then make several file edits or wait for a while. The EMFILE error will eventually crash the dev server.

System Info

  • WXT: 0.20.13 (latest)
  • chokidar: 4.0.3 (via WXT)
  • OS: macOS Darwin 25.2.0
  • Node: v22.x
  • ulimit -n: 65536

Validations

  • Read the Contributing Guidelines.
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug.
  • The provided reproduction is a minimal reproducible example of the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionA question about usage, not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions