目录
一、问题描述:
三年前,做electron项目的时候,选择了基于vue来构造electron应用程序的electron-vue,
最近因为开发新的功能对chrome版本有要求,需要升级electron,但是electron-vue的第三方依赖到
1.0.6版本已经放弃更新了,只能强制更新electron版本进行升级,
二、解决方案:
(1)下载之前的electron安装依赖,安装需要版本的electron,
npm uninstall electron
npm install electron
(2)配置相关参数,运行即可
nodeIntegration: true, // 在网页中集成Node
解决 require is not defined
enableRemoteModule: true, // 打开remote模块
contextIsolation: false // 是否在独立 JavaScript 环境中运行 Electron API和指定的preload 脚本
解决:Cannot read property 'app' of undefined
mainWindow = new BrowserWindow({
height: 720,
useContentSize: true,
width: 1280,
frame: true,
show: false,
webPreferences: {
webSecurity: false,
nodeIntegration: true, // 在网页中集成Node
enableRemoteModule: true, // 打开remote模块
contextIsolation: false // 是否在独立 JavaScript 环境中运行 Electron API和指定的preload 脚本
}
// transparent: true
});
三、注意事项:
BrowserWindow的参数说明:https://www.electronjs.org/docs/latest/api/browser-window
在 Electron 9 中,使用远程模块而不通过 enableRemoteModuleWebPreferences 选项显式启用它开始发出警告。在 Electron 10 中,远程模块现在默认禁用。要使用远程模块,enableRemoteModule: true必须在 WebPreferences 中指定:
const w = new BrowserWindow({
webPreferences: {
enableRemoteModule: true
}
})