I want to use Chokidar to watch files in my app. The problem is that electron throws an error whenever you try to instantiate chokidar.watch. I was wondering if this is a known compatibility issue between the two, as well as if there is a built in solution to solve this problem. Google yields nothing regarding watching files in an electron app so far. The error only occurs when using the chokidar object. Requiring it does not cause problems.
My code in the renderer process is below. Commenting out the var watcher code will eliminate the console error altogether. The code is directly from their docs.
var chokidar = remote.require('chokidar');
chokidar.watch('.', {ignored: /[\/\\]\./}).on('all', function(event, path) {
console.log(event, path);
});
console error:
Uncaught Error: criterion.test is not a function
TypeError: criterion.test is not a function
at testCriteria (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/node_modules/anymatch/index.js:29:26)
at Array.some (native)
at anymatch (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/node_modules/anymatch/index.js:59:48)
at EventEmitter.FSWatcher._isIgnored (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/index.js:221:15)
at EventEmitter.NodeFsHandler._addToNodeFs (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/lib/nodefs-handler.js:429:12)
at EventEmitter.<anonymous> (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/index.js:410:12)
at /Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/node_modules/async-each/index.js:16:7
at Array.forEach (native)
at each (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/node_modules/async-each/index.js:15:11)
at EventEmitter.FSWatcher.add (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/index.js:409:5)
Any advice on how to add watching to my project is much appreciated. Atom editor detects when files and folders are added using a file explorer, and appropriately displays up to date folder info in the sidebar. If atom can do it, so can my app!
This is probably breaking all rules of electron's remote objects - but you can try accessing the remote version of
chokidar
: