sass / dart-sass

The reference implementation of Sass, written in Dart.
https://sass-lang.com/dart-sass
MIT License
3.97k stars 360 forks source link

Error: EMFILE too many open files with watch flag #2362

Closed ryanb closed 1 month ago

ryanb commented 1 month ago

Since upgrading Sass to v1.79.2, the sass ... --watch command crashes after a few minutes with the following error.

$ sass --load-path=node_modules --load-path=app/frontend/stylesheets --no-source-map --quiet-deps --update app/frontend/entries/sass/:app/assets/builds/ --watch
Sass is watching for changes. Press Ctrl-C to stop.

Unexpected exception:
Error: EMFILE: too many open files, watch

When I run that command and list out which processes are using files with lsof | awk '{print $1}' | sort | uniq -c | sort -rn it shows node has 39,520 files open.

It may be because I have --load-path=node_modules, however this wasn't an issue with sass v1.78.0. When I downgrade back the number of open files for node stays around ~160.

It seems Sass v1.79 upgraded chokidar from v3.6 to v4.0 which I assume is causing this issue.

I'm on Mac OS X 14.6.1

nex3 commented 1 month ago

Please report this issue to Chokidar—we have very limited control over precisely how it works. In the meantime, you can force the dependency back to the 3.x line.

ryanb commented 1 month ago

@nex3 sounds like they won't be able to easily fix it in chokidar. Is it possible to separate watch path and load paths in sass? I only need node_modules in the load path, not watch the entire directory.

nex3 commented 1 month ago

Generic load paths are too often used for user source code to omit them from watching. I recommend using --pkg-importer=node to load package dependencies; that won't be covered by the watcher.

ryanb commented 4 weeks ago

Switching to --pkg-importer=node worked great. I just needed to prefix all package import paths with pkg:. Thanks!

Update: I just saw this comment about moving from chokidar: https://github.com/sass/dart-sass/issues/2373#issuecomment-2411793489

So this may also be why I'm no longer seeing this issue.