electron子进程使用主进程模块报错,引入就报错
const { BrowserWindow } = require('@electron/remote')
问题出现在子进程A中使用BrowserWindow创建了一个窗口页面子进程B,在子进程B中需要dialog,使用导入库const { dialog } = require('@electron/remote')报错如下
关键点
子进程A的界面在主进程中创建正常打开,不报错。
子进程B的界面是在子进程A创建正常打开,不报错。
但是在子进程B是引入dialog或者BrowserWindow就报错
主进程main.js关键代码
const { app, BrowserWindow,Menu } = require('electron')
app.commandLine.appendSwitch('--js-flags', '--harmony_proxies');
const path = require('path')
const createWindow = () => {
const mainWindow = new BrowserWindow({
width: 1280,
height: 800,
webPreferences: {
//preload: path.join(__dirname, 'preload.js'),
nodeIntegration:true, //允许渲染进程使用node.js
contextIsolation:false, //允许渲染进程使用node.js
// 开启remote
enableRemoteModule:true
},
})
require("@electron/remote/main").initialize();
require("@electron/remote/main").enable(mainWindow.webContents);
mainWindow.loadFile('index.html')
// 打开开发工具
// mainWindow.webContents.openDevTools()
}
进程A关键代码
window.onload = function () {
const { BrowserWindow } = require('@electron/remote')
//download
document.getElementById("download").onclick = function () {
newWin1 = new BrowserWindow({
width: 750,
height: 500,
backgroundColor: '#fff',
//resizable:false,
webPreferences: {
//preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true, //允许渲染进程使用node.js
contextIsolation: false, //允许渲染进程使用node.js
// 开启remote
enableRemoteModule: true
},
});
require("@electron/remote/main").enable(newWin1.webContents)
newWin1.loadFile("./addons/download/download.html");
require("@electron/remote/main").enable(webContents)
newWin1.on("closed", () => {
newWin = null;
});
};
};
进程B关键代码
var { clipboard } = require("electron");
const { BrowserWindow } = require('@electron/remote')
document.getElementById("button_choose").onclick = function () {
console.log("开始");
};
有人知道吗