2

Chokidar を使用してアプリ内のファイルを監視したいと考えています。問題は、chokidar.watch をインスタンス化しようとするたびに electron がエラーをスローすることです。これが 2 つの間の既知の互換性の問題であるかどうか、またこの問題を解決する組み込みのソリューションがあるかどうか疑問に思っていました。Google は、electron アプリでファイルを監視することに関して、これまでのところ何も提供していません。このエラーは、chokidar オブジェクトを使用している場合にのみ発生します。要求しても問題はありません。

レンダラー プロセスの私のコードは以下のとおりです。var ウォッチャー コードをコメント アウトすると、コンソール エラーが完全に解消されます。コードはドキュメントから直接です。

var chokidar = remote.require('chokidar');
chokidar.watch('.', {ignored: /[\/\\]\./}).on('all', function(event, path) {
  console.log(event, path);
});

コンソール エラー:

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)

私のプロジェクトに監視を追加する方法についてのアドバイスは大歓迎です。Atom エディターは、ファイル エクスプローラーを使用してファイルとフォルダーが追加されたことを検出し、サイドバーに最新のフォルダー情報を適切に表示します。アトムができるなら、私のアプリもできます!

4

1 に答える 1