Windows 7, Chokidar exits with error when remove a directory #88

jeromedecoster opened this Issue Dec 24, 2013 · 15 comments


None yet
6 participants


On Windows 7, lastest nodejs, latest chokidar

I have this simple test file:

var chokidar = require('chokidar');

var watcher ='./client', {persistent: true});

  .on('add', function(path) {console.log('File', path, 'has been added');})
  .on('addDir', function(path) {console.log('Directory', path, 'has been added');})
  .on('change', function(path) {console.log('File', path, 'has been changed');})
  .on('unlink', function(path) {console.log('File', path, 'has been removed');})
  .on('unlinkDir', function(path) {console.log('Directory', path, 'has been removed');})
  .on('error', function(error) {console.error('Error happened', error);})

When I run the script I have:

Directory ./client has been added

If I add a directory mkdir a, I have:

Directory ./client has been added
Directory client\a has been added

But if I remove the dir rm -rf ./a I have this error and the script exits

        throw er; // Unhandled 'error' event
Error: watch EPERM
    at errnoException (fs.js:1019:11)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1037:26)

paulmillr commented Dec 24, 2013

This is node.js core error joyent/node#4337

But we need to handle this one, yes

dwittner added a commit to dwittner/chokidar that referenced this issue Apr 1, 2014

Cominch commented Oct 1, 2014

Would you like to pull this fix into the main repository?

dwittner commented Oct 1, 2014

The fix is already merged into the main repository (#112), but unfortunately it got a few improvements, so that it isn't working any longer.

Cominch commented Oct 2, 2014

Bug see #112

@es128 es128 closed this in 2913fae Oct 10, 2014


es128 commented Oct 10, 2014

@dwittner please verify whether 2913fae does the trick

@es128, it seems to work now, at least i don't get an error anymore. Thus it is an improvement in any case. Can you tell me, when the fix will be released?

Cominch commented Oct 11, 2014

Additional comment: I had to put a try... catch around _handleFile and _handleDir calls in the _handle Subroutine, but unfortunately I was not able to track down the error in Detail.
I will try to investigate further, and try to identify the exception.


es128 commented Oct 11, 2014

I don't think I have npm rights on chokidar yet, but I'd probably want to take another week or so to fix any other issues I can track down and try to make sure it's stable before I recommend an 0.10 release.

Cominch commented Oct 11, 2014

even with my try... catch Approach, I don't manage to handle all "unhandled 'error' events"
two are still remaining: Unknown System errno 58 and Unknown Sytem errno 56
But this applies mainly to Networked shared Folders on Windows, which is also mentioned in multiple other issues

@Cominch, what are your test cases? With the solution of @es128, i can add and delete folders on Windows without any errors.

Cominch commented Oct 11, 2014

it's now limited to Windows Network Shares, and happens sporadically during the _handle.onchange Event.
As I programmatically open every detected added file with write and Change flags, it's limited to Change Events. Deleting seems to be painless now.

Cominch commented Oct 11, 2014

hm... i think now it says EPERM again while lstat'ting:

Cannot call method "emit" of undefined, in chokidar\index.js:294 tracing back to index.js:286, where it emits something ALTHOUGH I'm on Windows, and it clearly says ...raised an error: EPERM, lstat


es128 commented Oct 11, 2014

@Cominch please provide code and describe steps to reproduce

@es128, 0.10.1 works fine for me now. Thx a lot!

@cjzamora cjzamora referenced this issue in evelution/phonegap Dec 27, 2014


Chokidar 'watch EPERM' error. #4

kafoso commented Jun 10, 2016

Necro, but still relevant.

This error may be caused by deleting a file from within an application being run as a different user on the system. E.g. running a text editor as Administrator (Windows) and deleting the file from within this editor will trigger the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment