EBADF error when watching tons of files on macos
Author: bluwyCreated Nov 5, 2024Updated Nov 13, 2025
Describe the bug
When watching many files on macos. spawning a child process causes EBADF errors consistently. (likely due to reaching maximum file descriptors?)
Versions (please complete the following information):
- Chokidar version: v4
- Node version: 18, 20
- OS version: MacOS 15.1
To Reproduce:
https://github.com/bluwy/chokidar-lots-of-files-repro
Steps:
node gen.js(generate files in src/ to watch)node test.js(watches files and tries to run thelsbash command)
Expected behavior
EBADF errors should not appear when spawning a child process after watching tons of files.
Additional context
With chokidar v4 removing fsevents and using fs.watch, this issue is blocking Vite and Nuxt from upgrading to v4 as there's no easy workaround to the problem (other than usePolling).
- https://github.com/vitejs/vite/issues/18527
- https://github.com/nuxt/nuxt/issues/29744 (has Nuxt-specific repro, which I believe relied on
unstoragev1.13.0 that uses chokidar v4) - https://github.com/unjs/unstorage/pull/502
Users have also tried adjusting ulimit to extend the maximum file descriptors, but it didn't fix the issue.
Source: paulmillr/chokidar