Skip to content

Files not detected if directory does not exist before watching #1422

@Ehesp

Description

@Ehesp

Describe the bug

Directories which don't exist before starting the watcher are not detected.

Versions (please complete the following information):

  • Chokidar version 4.0.3
  • Node version 23.6.0
  • OS version: debian:bullseye-slim

To Reproduce:

I've got a watcher looking at /home/sandbox.

Before I start the watcher, some files on FS already exist on /home/sandbox/project/.... When the watcher kicks off, it notifies me about all of these files as expected. After a few seconds, a process creates some more files on my filesystem, e.g:

  1. /home/sandbox/project/.foo/bar.txt
  2. /home/sandbox/.baz/hello.txt

My watcher successfully notifies me about file 1, but does not trigger any changes about file 2.

const watcher = chokidar.watch('/home/sandbox', {
    persistent: true,
    ignoreInitial: false,
    followSymlinks: true,
});

watcher.on('all', (event, filePath) => {
  console.log('[chokidar] all', filePath);
  // only logs /home/sandbox/project/.foo/bar.txt
});

If however, I create the directory before starting the watcher, I get notified about both files:

// Create the directory first
await fs.mkdir('/home/sandbox/.baz', { recursive: true });

const watcher = chokidar.watch('/home/sandbox', {
    persistent: true,
    ignoreInitial: false,
    followSymlinks: true,
});

Now if any files are created inside of /home/sandbox/.baz I get notified

Expected behavior

It picks up changes even if its a new directory

Additional context

Not sure if relevant, but the . directory names are intentional. I have tried a bunch of config options, ignore regex/callbacks but they never register the directory in the first place.

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