Error: EMFILE: too many open files
Current behavior
When using plugin on macOS, the following error occurs after a dev build, in projects with many files:
No typescript errors found.
node:internal/errors:563
ErrorCaptureStackTrace(err);
^
Error: EMFILE: too many open files, watch
at FSWatcher._handle.onchange (node:internal/fs/watchers:207:21)
Emitted 'error' event on FSWatcher instance at:
at FSWatcher._handleError (/path/to/project/node_modules/chokidar/index.js:539:18)
at NodeFsHandler._boundHandleError (/path/to/project/node_modules/chokidar/handler.js:300:49)
at /path/to/project/node_modules/chokidar/handler.js:149:9
at foreach (/path/to/projectnode_modules/chokidar/handler.js:81:9)
at fsWatchBroadcast (/path/to/project/node_modules/chokidar/handler.js:148:5)
at FSWatcher.<anonymous> (/path/to/project/node_modules/chokidar/handler.js:196:17)
at FSWatcher.emit (node:events:518:28)
at FSWatcher._handle.onchange (node:internal/fs/watchers:213:12) {
errno: -24,
syscall: 'watch',
code: 'EMFILE',
filename: null
}
Node.js v20.11.0
This error seems to be related to the chokidar file watcher used internally, likely due to hitting macOS restrictions on open file descriptors.
🔎 Note: The output (build) directory and node_modules are excluded from the TypeScript and Webpack configs
Expected behavior
There should be no EMFILE: too many open files error during plugin execution on macOS.
Steps to reproduce the issue
- Use the plugin in a project where a directory contains a large number of files.
- Start the dev server on macOS.
Environment
- fork-ts-checker-webpack-plugin: ^9.0.2
- typescript: ^5.6.2
- eslint: ^9.9.1
- webpack: 5.94.0
- os: macOS Sohoma 14.5 (23F79)
👋 I'm also running into this, but specifically only after updating to [email protected]. If I roll back to [email protected], it does not crash.
Looking at https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/compare/v9.0.3...v9.1.0 leads me to suspect https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/commit/147aa11bcac1cb4478280663ac5b4642a54c2fc8 is the cause? I see https://github.com/paulmillr/chokidar/issues/1369, which discusses EMFILE issues in v4.
Same here! rolling back to [email protected] solves the issue
Thanks @MattIPv4 for the solution! 🙌
Should we close this issue now or wait for maintainers to review/merge your PR first?
I don't have a PR to fix the issue -- I'm not sure what the best fix would be, perhaps using graceful-fs, but I leave that to the maintainers.
Fwiw, there are two watchOptions Webpack settings that also seem to be a workaround for this as also suggested in the upstream chokidar issue (though I do not consider them a fix given this is a clear regression between 9.0.3 and 9.1.0):
watchOptions: {
ignored: /node_modules/,
},
watchOptions: {
poll: 1000,
},
+1