Skip to content

🐛 Bug: Not able to watch files with huge node_modules anymore after bumping chokidar to v4 #5374

@nescalante

Description

@nescalante

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have 'smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

mocha --watch should work with big node_modules codebases

Actual

mocha --watch stopped to work with big node_modules codebases

Minimal, Reproducible Example

After merging #5256 I am not able to watch files anymore and instead I am receiving this error:

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 (/Users/nescalante/dev/exchange-ui/node_modules/mocha/node_modules/chokidar/index.js:540:18)
    at NodeFsHandler._boundHandleError (/Users/nescalante/dev/exchange-ui/node_modules/mocha/node_modules/chokidar/handler.js:302:49)
    at /Users/nescalante/dev/exchange-ui/node_modules/mocha/node_modules/chokidar/handler.js:149:9
    at foreach (/Users/nescalante/dev/exchange-ui/node_modules/mocha/node_modules/chokidar/handler.js:81:9)
    at fsWatchBroadcast (/Users/nescalante/dev/exchange-ui/node_modules/mocha/node_modules/chokidar/handler.js:148:5)
    at FSWatcher.<anonymous> (/Users/nescalante/dev/exchange-ui/node_modules/mocha/node_modules/chokidar/handler.js:197:17)
    at FSWatcher.emit (node:events:517:28)
    at FSWatcher._handle.onchange (node:internal/fs/watchers:213:12) {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  filename: null
}

Node.js v18.20.8

This is because now the watcher is being initialized this way:

const watcher = chokidar.watch('.', {
  ignoreInitial: true
});

and that is causing chokidar to do a watch in the whole directory

Versions

Edit by @mark-wiemer:
Mocha ^11.2.2
Node 18.20.8

Additional Info

No response

Metadata

Metadata

Assignees

Labels

status: accepting prsMocha can use your help with this one!type: buga defect, confirmed by a maintainer

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions