Skip to content

Chokidar reports a "change" event for *all* files when just one file is changed (using Deno) #1417

@MrPixel1

Description

@MrPixel1

Describe the bug

Chokinar reports too many events: When a file in the watched directory is changed, Chokinar reports a change for every file.

This causes lots of issues and crashes when used in conjunction with Vite.

I use Deno on Linux.

Directory with some files:

.rw-r--r--  195 app-test.vue
.rw-r--r--  123 chokidar.ts
.rw-r--r--    3 deno.json
.rw-r--r-- 3,2k deno.lock
.rw-r--r--    0 irrelevant.json
.rw-r--r--    0 irrelevant.ts

The file chokidar.ts has the following contents:

import chokidar from "npm:chokidar@4.0.3"; // I changed the version here for different tests
chokidar.watch(".").on("all", (event, path) => {
        console.log(event, path);
});

Start chokidar:

$ deno --allow-env --allow-read chokidar.ts
addDir .
add deno.json
add irrelevant.ts
add irrelevant.json
add app-test.vue
add deno.lock
add chokidar.ts

Then, touch app-test.vue - all good so far:

change app-test.vue

But if I change the file with sed -i 's/test/tset/g' app-test.vue, Chokidar reports a change for all files:

change irrelevant.json
change app-test.vue
change deno.lock
change chokidar.ts
change deno.json
change irrelevant.ts

I also checked out this repository and ran tests. Tests fail at "thirtythree" (as indicated in #1411, not sure if it's related to this problem).

$ deno install
...

$ deno --allow-env --allow-read --unstable-sloppy-imports src/index.test.mts
✅ Granted write access to "/tmp/chokidar-1739094660884".
205 tests started...
chokidar
├─should expose public API methods: ☆
│ should expose public API methods: ✓
├─fs.watch (non-polling)
│ ├─watch a directory
│ │ ├─should produce an instance of chokidar.FSWatcher: ☆
│ │ │ should produce an instance of chokidar.FSWatcher: ✓
│ │ ├─should expose public API methods: ☆
│ │ │ should expose public API methods: ✓
│ │ ├─should emit `add` event when file was added: ☆
│ │ │ should emit `add` event when file was added: ✓
│ │ ├─should emit nine `add` events when nine files were added in one directory: ☆
│ │ │ should emit nine `add` events when nine files were added in one directory: ✓
│ │ ├─should emit thirtythree `add` events when thirtythree files were added in nine directories: ☆
│ │ │ should emit thirtythree `add` events when thirtythree files were added in nine directories: ☓
error: Uncaught (in promise) Error: timeout waitFor, passed ms: 32000
      reject(new Error('timeout waitFor, passed ms: ' + TEST_TIMEOUT));
             ^
    at file:///home/leme/projects/playgrounds/chokidar/src/index.test.mts:171:14
    at callback (ext:deno_web/02_timers.js:58:7)
    at eventLoopTick (ext:core/01_core.js:212:13)

Versions (please complete the following information):

  • Chokidar version: 4.0.3, 3.6.0 and 3.0.0 (these are the versions I tested)
  • Deno version: 2.1.7
  • OS version: Arch Linux

Expected behavior
Just a "change" event for changed files, not for other files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions