Skip to content

Error: EMFILE: too many open files #859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Ten666u opened this issue Apr 14, 2025 · 6 comments
Open

Error: EMFILE: too many open files #859

Ten666u opened this issue Apr 14, 2025 · 6 comments
Labels

Comments

@Ten666u
Copy link

Ten666u commented Apr 14, 2025

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

  1. Use the plugin in a project where a directory contains a large number of files.
  2. 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)
@Ten666u Ten666u added the bug label Apr 14, 2025
@MattIPv4
Copy link

MattIPv4 commented Apr 14, 2025

👋 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 v9.0.3...v9.1.0 leads me to suspect 147aa11 is the cause? I see paulmillr/chokidar#1369, which discusses EMFILE issues in v4.

@fslzrr
Copy link

fslzrr commented Apr 14, 2025

Same here! rolling back to [email protected] solves the issue

@Ten666u
Copy link
Author

Ten666u commented Apr 14, 2025

Thanks @MattIPv4 for the solution! 🙌
Should we close this issue now or wait for maintainers to review/merge your PR first?

@MattIPv4
Copy link

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.

@MattIPv4
Copy link

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,
  },

@johaven
Copy link

johaven commented Apr 24, 2025

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants