gajus / turbowatch

Extremely fast file change detector and task orchestrator for Node.js.
Other
943 stars 23 forks source link

Chokidar watcher is watching all files in the project instead of matched ones #32

Closed momirov closed 1 year ago

momirov commented 1 year ago

When starting turbowatch chokidar is watching all files in the project directory which produces this error

Error: ENOSPC: System limit for number of file watchers reached

I'm using linux.

Expected Behavior

Chokidar should watch only files that match expression defined in configuration.

Current Behavior

Chokidar is watching all files, even the ones excluded by configured expression. Some developers use Webstorm and it creates watchers for .idea config even.

Possible Solution

Apply expression filters on a file list before sending it to chokidar, that way only files that match expressions are watched.

Steps to Reproduce

Start the watcher in larger project.

Logs

Error: ENOSPC: System limit for number of file watchers reached, watch '/project/src/node_modules/@typescript-eslint/utils/dist/eslint-utils/applyDefault.d.ts.map' at FSWatcher.<computed> (node:internal/fs/watchers:247:19) at Object.watch (node:fs:2315:34) at createFsWatchInstance (/project/src//node_modules/chokidar/lib/nodefs-handler.js:119:15) at setFsWatchListener (/project/src//node_modules/chokidar/lib/nodefs-handler.js:166:15) at NodeFsHandler._watchWithNodeFs /project/src/node_modules/chokidar/lib/nodefs-handler.js:331:14) at NodeFsHandler._handleFile /project/src/node_modules/chokidar/lib/nodefs-handler.js:395:23) at NodeFsHandler._addToNodeFs (/project/src/node_modules/chokidar/lib/nodefs-handler.js:637:21) Emitted 'error' event on FSWatcher instance at: at FSWatcher._handleError (/project/src/node_modules/chokidar/index.js:647:10) at NodeFsHandler._addToNodeFs (/project/src/node_modules/chokidar/lib/nodefs-handler.js:645:18) {

gajus commented 1 year ago

That won't work unfortunately. The files might not even exist when watcher starts.

You have three options that I can think of:

  1. use alternative backend
  2. upgrade to Node.js 19.1 (and use FSWatcher backend)
  3. narrow down project to a smaller set of files
gajus commented 1 year ago

Closing the issue as this behavior is by design, but happy to continue the conversation.