带有 browserWindow 和 preload.js 的电子生成器.无法加载预加载脚本 [英] electron-builder with browserWindow and preload.js. Unable to load preload script
问题描述
我的 main.js 中的 electron-builder 和 browserWindows 预加载选项有问题:
i`ve a problem with electron-builder and the browserWindows preload option in my main.js:
// Create the browser window.
mainWindow = new BrowserWindow({
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height,
minHeight: 500,
minWidth: 1000,
icon: path.join(__dirname, 'icon.ico'),
frame: false,
webPreferences: {
preload: path.resolve(__dirname, 'preload.js'), // <--- PROBLEM
nativeWindowOpen: true,
spellcheck: true,
nodeIntegration: false
}
});
启动打包的应用程序后,我收到以下错误:
after starting the packaged app i get the following error:
无法加载预加载脚本:C:Users[...] esourcesapp.asarpreload.js
preload.js 与 main.js 位于同一目录中.
The preload.js is in the same directory as the main.js.
有解决这个问题的想法吗?
Any ideas to solve this problem?
诚挚的问候,凯W.
推荐答案
webPreferences: {
frame: false,
nodeIntegration: true,
enableRemoteModule: true, //this must be true
preload: path.resolve(root, 'bridge', 'initialize.js'),
}
无法加载预加载脚本,但实际上 initialize.js 有问题.在我的文件中,有一个错误,remote.getGlobal 未定义,因为这个 webPreferences.enableRemoteModule 在 10.x 版本的默认值是 false,所以你必须将它设置为 true.那么它会很好用.
Unable to load preload script, but actually something was wrong with the initialize.js. in my file, has an error that remote.getGlobal is undefined, because this webPreferences.enableRemoteModule's default value is false at the version 10.x, so u must set it with true. then it will work good.
这篇关于带有 browserWindow 和 preload.js 的电子生成器.无法加载预加载脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!