Error: EMFILE: too many open files, watch

This has been annoying me for some time:

Error from chokidar (/home/brian/tree/personal/relixir/robotica/robotica_face/assets/node_modules/css-loader/dist/runtime): Error: EMFILE: too many open files, watch '/home/brian/tree/personal/relixir/robotica/robotica_face/assets/node_modules/css-loader/dist/runtime/api.js'

This message gets displayed for every file in the assets directory, when starting the dev instance. If I stop other running programs, close browser tabs, it will come good temporary, but then go bad again. Only sure fix is to reboot my computer.

Phoenix is the only thing that seems to be affected, and as far as I can tell it isn’t actually affecting running of the application.

My computer is Debian/bullseye.

This is the only running copy of elxir running on this computer.

Wondering if there is something on my system - maybe even the Linux kernel - that is leaking open files.

Have you checked your total limit of how many open files can you have at maximum?

Did You make any changes to the watchers configuration?

No. I didn’t make any changes. Apart from changing --watch-stdin with --watch.

Did You change this for Webpack 5?

Maybe like this?

    node: [
      "node_modules/webpack/bin/webpack.js",
      "--mode",
      "development",
      "--watch",
      "--watch-options-stdin",
      cd: Path.expand("../assets", __DIR__)
    ]
1 Like

Hmmm. I am not familiar with this --watch-options-stdin. The info I saw - somewhere - strongly implied I should drop --watch-stdin.

e.g. the top two google results for watch-stdin:

Which links to the fix:

From the docs:for watch-options-stdin:

Stop watching when stdin stream has ended

Apparently I have 90 copies of webpack running. Oh, that would explain it.

Will make the change, kill my webpacks, and hopefully that will fix this.

Thanks!

It would be good if there was an authoritative source somewhere of correct changes required to the webpack stuff from the standard phoenix template.

See also Webpack error after upgrading mini-css-extract-plugin@1.6.2 - #3 by derek-zhou for an example of just another problem this has caused me.

You might find reference here…

Good point. I guess I should compare my assets directory with the values from the git source at phoenix/installer/templates/phx_assets at master · phoenixframework/phoenix · GitHub

Sounds like Pheonix is now switching to using esbuild. https://twitter.com/josevalim/status/1417017859847475201