chokidar: Node doesn't exit after closing watch

After setting up, then closing, a watcher, the Node process doesn’t exit. Windows.

const chokidar = require('chokidar')
const options = {}
const directoryPath = srcPath
// configuration taken from webpack
const watcher = chokidar.watch(directoryPath, {
    ignoreInitial: true,
    persistent: true,
    followSymlinks: false,
    depth: 0,
    atomic: false,
    alwaysStat: true,
    ignorePermissionErrors: true,
    usePolling: options.poll ? true : undefined,
    interval: typeof options.poll === "number" ? options.poll : undefined
});
watcher.close()

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 4
  • Comments: 32

Commits related to this issue

Most upvoted comments

I confirm the problem. No nested directories are required. A simple code to reproduce:

var chokidar = require('chokidar');

var fn = function ( name ) {
    console.log('change: ' + name);
};

var watcher = chokidar.watch('./*')
    .on('change', fn)
    .on('unlink', fn)
    .on('add',    fn);

setTimeout(function () {
    console.log('should exit!');
    watcher.close();
}, 10000);

Interesting point to note - just run the code above and wait doing nothing - it will exit the node process in 10 seconds without any problems. It will NOT exit in case there will be some file modifications in the current dir before watcher.close. So even once change/unlink/add are triggered and this hangs the process.