2017-10-11 48 views
0

我正在使用样板react-photonkit/epp,并且在运行yarn start时,一切都在dev上很好地执行。电子未定义

但是,当我想打包我的应用程序yarn run build-osx时,应用程序已生成,但启动时出现错误。此错误仅在我尝试导入电子时出现。如果没有,该应用程序正在生产中运行。

Uncaught ReferenceError: electron is not defined

这里是我的webpack config,我加入的唯一的事情是target:"electron"。我也试过externals: {electron: "electron"}

我试图从电子导入对话框这样的:

const {dialog} = require('electron').remote; 

或者

const {dialog} = window.require('electron').remote; 

回答

0

我设法所需的对话框修改目标中的WebPack配置targe:electron-renderer,其导入模块远程。

然后,我们可以导入像这样

const remote = window.require("electron").remote; 
const dialog = remote.require('dialog'); 

而且我可以从电子使用对话框。这是一种解决方法,我没有弄清楚为什么电子不可用,但可能是因为electronelectron-packager的真正旧版本。这个回购一段时间没有更新,版本也没有修复,所以会产生问题。

无论如何,对于试用此样板的人来说,请从electron forgeelectron-compile开始!

相关问题