webpack: [Webpack 5] Error: EMFILE, too many open files in watch mode

Bug report

What is the current behavior? When I run webpack 5 in watch mode(or webpack-dev-server), webpack compiles my project successfully, but then I start getting the error Error: EMFILE, too many open files in watch mode. The terminal tab gets stuck and I am not able to close the process by using (ctrl+c). I have to close the terminal tab

If the current behavior is a bug, please provide the steps to reproduce. I investigated and found that the bug is due to this plugin WatchMissingNodeModulesPlugin. It used to work correctly with Webpack 4. On removing this plugin, everything works correctly. I think the issue is when webpack tries to watch large number of files

What is the expected behavior? Webpack’s watch should not fail with the above mentioned error.

Other relevant information: webpack version: 5.0.0-beta.22 Node.js version: v12.17.0 Operating System: MacOS 10.15.6

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

This issue is reproducible. I have created a minimum reproducible example here.

Steps to setup:

  1. yarn
  2. yarn start
  3. Navigate to http://localhost:8080/

Expected output => ["extract","parse","stringify","parseUrl","stringifyUrl"]

Steps to reproduce:

  1. Make changes to node_modules/query-string/index.js file
  2. Add exports.abcd = "test" (or anything else, while the dev server is still running).
  3. Observe the console in the browser.
  4. The output in the browser does not change.

Add this line(cache.managedPaths = []) in webpack.config.js(or just uncomment the cache block), and repeat the above steps. The output in the browser changes