electron获取不到remote
electron获取不到remote
问题
// 渲染进程
let remote = require('electron').remote
console.log(remote) // undefined
原因
版本问题,可以看到在老的版本的说明文档里面还有这个,在新的版本的说明文档里面没有这个了
解决
实际是remote模块默认关闭, 必须手动设置webPreferences中的enableRemoteModule为true之后
mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
// 在electron 10.0.0之后,remote模块默认关闭
// 必须手动设置webPreferences中的enableRemoteModule为true之后才能使用
enableRemoteModule: true, // 这里是关键设置
},
// 其他设置...
});

浙公网安备 33010602011771号