Persistent watch stopped after watched directory is removed
Author: tgrajewskiCreated May 25, 2026Updated May 25, 2026
Describe the bug
I watch a single directory with a single file in it. When I remove the directory while it's being watched using File Explorer in Windows, I get proper events, but persistent watching stops and I get back to command line (Node.js process stops?).
Versions:
- Chokidar v5.0.0
- Node v24.15.0
- Windows 11
To Reproduce:
Run the code below, but first create static directory and maybe add a small file to it (I don't think the file matters here).
const process = require('node:process');
const chokidar = require('chokidar');
const watcher = chokidar.watch(['./static'], {'ignoreInitial': true, 'cwd': process.cwd()});
watcher.on('add', function(path) { console.log('add', path); });
watcher.on('change', function(path) { console.log('change', path); });
watcher.on('unlink', function(path) { console.log('unlink', path); });
watcher.on('addDir', function(path) { console.log('addDir', path); });
watcher.on('unlinkDir', function(path) { console.log('unlinkDir', path); });
watcher.on('error', function(path) { console.log('error', path); });
setTimeout(function() {
fs.unlinkSync('./static/favicon.ico');
fs.rmdirSync('./static');
}, 3000);Output from the above is:
unlinkDir static
unlink static\favicon.icoAfter last message process stops.
Expected behavior
Node.js process would not stop and continue watching files, especially for case when directory static is added again.
Source: paulmillr/chokidar