Skip to content

Inconsistent, and undocumented, behavior when unwatching child directory and watching parent directory #1439

@abrahamguo

Description

@abrahamguo

Describe the bug

When unwatching a child directory and adding a parent directory, chokidar has inconsistent behavior depending on whether a relative or absolute path is provided.

Neither of these behaviors are specifically documented, and it's unclear which is the correct behavior (or whether they are both correct).

With relative paths:

import { watch } from 'chokidar';

const a = `a`;
const b = `${a}/b`;
watch(b).unwatch(b).add(a).on(`change`, () => console.log(`change!`));

The change event is fired for everything in a, including in b.

With absolute paths:

import { watch } from 'chokidar';

const { dirname } = import.meta;
const a = `${dirname}/a`;
const b = `${a}/b`;
watch(b).unwatch(b).add(a).on(`change`, () => console.log(`change!`));

The change event is fired for everything in a, except in b.

Versions (please complete the following information):

  • Chokidar version: 4.0.3
  • Node version: 24.6.0
  • OS version: macOS 15.6

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