Loading...

Electron12版本以上解决dlopen加载.node 文件失败问题?

问题描述

在Electron12版本以上使用小鱼Electro SDK,可能会产生如下报错:

TypeError: Cannot read property 'dlopen of undefined

此问题是Electron@12版本开始,默认启用了上下文隔离开关,详见:​​​​​​上下文隔离​​;​

解决方法

我们需要主动关闭上下文隔离操作,在项目主进程文件下修改配置,设置 contextIsolation 为 false:

const window = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: true,
// 关闭上下文隔离
contextIsolation: false,
}
// ...
});


意见反馈