如何在Electron App中查看文件?

我想使用Chokidar在我的应用程序中观看文件。问题是,只要你尝试实例化chokidar.watch,电子就会抛出一个错误。我想知道这是否是两者之间的已知兼容性问题,以及是否有内置解决方案来解决此问题。 Google迄今为止没有在电子应用程序中观看文件。只有在使用chokidar对象时才会出现此错误。要求它不会导致问题。如何在Electron App中查看文件?

我在渲染过程中的代码如下。注释掉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编辑器使用文件资源管理器检测文件和文件夹的添加时间,并在侧边栏中适当地显示最新的文件夹信息。如果原子能做到这一点,我的应用程序也能做到!

回答:

这可能破坏电子的远程对象的所有规则 - 但你可以尝试访问的chokidar远程版本:

var chokidar = global\['require'\]('remote').require('chokidar'); 

以上是 如何在Electron App中查看文件? 的全部内容, 来源链接: utcz.com/qa/265403.html

回到顶部