#1439·chokidar

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

Author: abrahamguoCreated Sep 22, 2025Updated Mar 30, 2026

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