Replacing watched directory with a file of the same name hangs process
Author: tgrajewskiCreated May 25, 2026Updated May 25, 2026
Describe the bug
When I replace watched directory with a file with the same name, the Node.js process hangs (goes into infinite loop?).
Versions:
- Chokidar v5.0.0
- Node v24.15.0
- Windows 11
To Reproduce:
Run the code below, but before that create the static directory manually.
const process = require('node:process');
const fs = require('node:fs');
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.rmdirSync('./static');
fs.writeFileSync('./static', '');
}, 3000);There is no output from the above code on my end.
Expected behavior
Process does not hang and report appriopriate events.
Source: paulmillr/chokidar