paulmillr / chokidar

Minimal and efficient cross-platform file watching library
https://paulmillr.com
MIT License
11.04k stars 586 forks source link

New files are not detected #1361

Open S-Stanley opened 2 months ago

S-Stanley commented 2 months ago

Describe the bug

We have a desktop app using electron@32.0.1. Chokidar is used to detect new file created in a specific directory. After upgrading from 3.6.0 to 4.0.0, new files are not detected 2/3 of the time.

Versions (please complete the following information):

To Reproduce:

  1. Upgrade to chokidar@4.0.0
  2. Add a new file in the directory watched
watcher = chokidar.watch("~/example-directory", {
  ignored: /(^|[/\\])\../,
  persistent: true,
  ignoreInitial: true,
});
watcher.on("add", path => {
 // this function is not triggered 2/3 times when a new file is created in the directory
})

Expected behavior

Chokidar detect the new file added in the directory watched

Additional context

Downgrading to 3.6.0 solved the issue for us

paulmillr commented 2 months ago

Try removing “ignored” and seeing what happens.

S-Stanley commented 2 months ago

Thanks for your quick answer, I feel like it's better, working 1/2 times but not everytime

43081j commented 2 months ago

I'll have a look when I'm next on a laptop too

The underlying logic hasn't actually changed much since 3.x other than removing glob support. So I am surprised you're seeing a difference in behaviour

S-Stanley commented 2 months ago

Thanks, let me know if you need more informations

I will take a look on the weekend as well

seans84 commented 2 months ago

I'm experiencing a similar error in a Rails project as well. New JavaScript is not detected when added to any existing or new files. Old, cached assets, are being served instead.

Downgrading back to 3.6.0 solves this issue.

I did notice something strange. In my lock file I now have two references to chokidar

Screenshot 2024-09-24 at 10 50 59 AM

I'm not sure if this is the cause of the issue or not.

DominoPivot commented 1 month ago

This bug also affects change events when performing atomic writes, which are occasionally replaced with unlink events. 😬

This took me a while to debug, because it's my first time using chokidar and this was the output of my build script (all files were deleted, then recreated):

Starting watcher.
Removing stale files.
Running esbuild.
m out\stylesheets\style.css
m out\oranges\popover.js    
m out\oranges\popover.js.map
- out\nosdk.js
- out\nosdk.js.map
- out\sdk.js
- out\sdk.js.map
m out\oranges\popover.js.map
- out\stylesheets\style.css.map

The rebuild happened fast enough for changes to be considered atomic, but most of the writes weren't detected by chokidar. Combine that with the fact (arguably a bug) that atomic change events are fired without delay, and the fact esbuild sometimes writes to the same file twice, and you get an output that gives the impression you forgot to wait for all deletions to be done before running the build, even though you did 🙃

panoply commented 6 days ago

Experience same issue with v4 - new files are not being picked up. Reverting to v3.6.0 solves the issue.