Skip to content

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

Description

@richterdennis

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    libuvIssues and PRs related to the libuv dependency or the uv binding.watch-modeIssues and PRs related to watch mode.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions