Chokidar: Ignored directories not being ignored

Created on 26 Oct 2018  路  13Comments  路  Source: paulmillr/chokidar

Describe the bug
Ignored does not ignore all files in all subdirectories of the ignored paths. For example, **/node_modules/**/* does not ignore files in **/node_modules/.staging/**/*

This can be checked by watching a typical JS project that uses npm, and then running npm install in that directory. You will receive file added events for files in node_modules/.staging which is incorrect.

I tried a lot of permutations of the ignored paths, such as **/node_modules which did not work either.

Versions (please complete the following information):

  • Chokidar version [e.g. 2.0.4, or commit hash] 2.0.4
  • Node version [e.g. 10.4.1] 8.11.1
  • OS version: [e.g. Ubuntu 16.04, or Windows 10] OS X 10.13.3

To Reproduce
Steps to reproduce the behavior.

var chokidar = require('chokidar');
var fs = require('fs');
// One-liner for files and directories starting with 'test'
const watcher = chokidar.watch(path, {
  ignored:  ['**/node_modules/**/*', '**/.git/**/*'],
  ignoreInitial: true,
  ignorePermissionErrors: true,
  followSymlinks: true,
  interval: 1000,
  binaryInterval: 1000,
});

Expected behavior
All files in any node_modules directory and any subdirectory in any node_modules directory will be ignored.

Additional context
I was able to work around the issue by using the function form of ignored to simply reject any path that has node_modules in it.

mac

Most helpful comment

I am facing similar issues.I want to watch the absolute path "some/folder" but ignore a "build" subfolder of that directory ("some/folder/build")

chokidar.watch('some/folder/', {
  ignored: ['some/folder/build']
}).on(...);

All 13 comments

This seems to be only affecting OSx, I can reproduce it there but not on Linux nor Windows. Actually none of the glob patterns inside ignored do work so even stuff like *.txt.

Node: 8.9.1
OSX: 10.14

@mlynch try adding the option useFsEvents: false to chokidars watch. It works this way for me on Mac

macOs 10.14.1
useFsEvents: false doesn't seem works to me

I am facing similar issues.I want to watch the absolute path "some/folder" but ignore a "build" subfolder of that directory ("some/folder/build")

chokidar.watch('some/folder/', {
  ignored: ['some/folder/build']
}).on(...);

Seeing a version of this on OSX. At least simple file globs are working but regular expressions are not.

I do get events for '.git/index' for the regex /^\.git\// and /^\.git\/.*/ (among other variants).

I don't get events if I include '.git\/**' in the ignore list.

I'm experiencing same issue.
OSX: 10.14.5
node: 12.4.0
Next code:

const baseDir = __dirname;
const ignored = ['node_modules/**/*'].map(glob => path.resolve(baseDir, glob));
watcher = chokidar.watch(baseDir, { ignored });

Fires events for all files in node_modules.

For those who looks for workaround: you can pass function as ignored parameter and filter paths manually. Example:

chokidar.watch(watchPath, {
   ignored: (path) => path.includes('node_modules')
});

I can't seem to stop chokidar from watching my .git directory which in turn is choking (hue hue) my electron.

This answer doesn't work for me. I'm trying ignore all .m.css.d.ts files. I tried the following:

var watcher = chokidar.watch('src/*/*', {
    ignored: (path) => {
        return path.includes('.m.css.d.ts');
    }, persistent: true
  })

I'm using MacOS Version 10.14.5

To further @RayzRazko's helpful snippet, you could ignore a variety of string includes in this fashion:

chokidar.watch(watchPath, {
   ignored: path => ["node_modules", "another_dir"].some(s => path.includes(s))
});

But it might be a regex situation if you want anything more robust

Works correctly for me with the latest [email protected] (master). Ensure you have node.js 8.16 or higher.

require('chokidar').watch('src/**/*', {
  ignored: (path => path.includes('hello'))
  persistent: true
}).on('all', (event, path) => { console.log(event, path); })

have some issue
macOS: 10.15.4
node: 13.6.0

For those who looks for workaround: you can pass function as ignored parameter and filter paths manually. Example:

chokidar.watch(watchPath, {
   ignored: (path) => path.includes('node_modules')
});

not work as expected

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RedMickey picture RedMickey  路  4Comments

Pomax picture Pomax  路  3Comments

rcarmich picture rcarmich  路  4Comments

jwahlin picture jwahlin  路  7Comments

Tilogorn picture Tilogorn  路  6Comments