Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs.watch emitting file change when file getting read after some time #50920

Open
richterdennis opened this issue Nov 26, 2023 · 1 comment
Open

Comments

@richterdennis
Copy link

richterdennis commented Nov 26, 2023

Version

v20.10.0

Platform

Microsoft Windows NT 10.0.22621.0 x64

Subsystem

No response

What steps will reproduce the bug?

Create file index.mjs in a random folder of your system (I am using Win 11) with files in it.

index.mjs content:

import { watch } from 'node:fs';

const watcher = watch('./', { recursive: true });
watcher.on('change', (eventType, fileName) => console.log(eventType, fileName));

Open a console and run node index.mjs

Then just browse through the folders and files and maybe open files with your IDE.

If I open a file from a random project I get for example:

change src\Config.js

Just by opening it.

fs.watch is also used in the node --watch implementation which is causing multiple reloads just because VS Code is reading some files.

How often does it reproduce? Is there a required condition?

The event occurs on the first read and then after some time. I don't know more details.

What is the expected behavior? Why is that the expected behavior?

The expected behavior is not triggering a change event when nothing changed.

What do you see instead?

Getting a change event triggered by opening a file..

Additional information

Sometimes there is also a

change null
@belauzas
Copy link

This behavior is truly random and I couldn't understand why...
P.S. I am using v.18.16.1 on win10x64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants