不支持Electron 20吗
Describe the bug
蛮尝试了下升级electron到20.1.2,发现模板(vue, ts) 跑不起来(下图),是目前还不支持20吗?还是有其它相关依赖需要同时升级?
另外我也蛮试了下降级electron到18,是正常的,请问目前支持的electron有明确的版本范围吗?
Electron-Vite Version
1.0.7
Electron Version
20.1.2
Vite Version
3.0.9
Validations
- [X] Follow the Code of Conduct.
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Electron 20 应该开启了一些新特性,待我测试一下
@joyexpr 可以翻阅 https://www.electronjs.org/blog/electron-20-0 , 20版本后都将默认开启沙箱模式
If your preload scripts do not depend on Node, no action is needed. If your preload scripts do depend on Node, either refactor them to remove Node usage from the renderer, or explicitly specify sandbox: false for the relevant renderers.
意思预载脚本如果依赖node,要不去除node依赖使用,要不就是对应渲染器显式指定 sandbox: false
electorn 的安全要求越来越高,沙箱的启用也是安全的设定,要求脚本不能具有node能力,其实也是好的。当然很多开发做不到。
处理方式有两个:
BrowserWindow中
webPreferences: {
sandbox: false
}
electron.vite.config.ts中,去除external,将依赖模块一起打包到preload中
export default defineConfig({
...
preload: {},
...
})
把外部依赖一起打包也是有条件的,也就是外部包不具有node的能力,如果有也是不行的(@electron-toolkit/preload没有node依赖,所以可以)
后续会更新脚手架,更改这些配置
了解了,感谢 [强]
我刚刚用 pnpm create @quick-start/electron 创建了新项目,并手动把依赖的 electron 版本升级到了最新的 20 。然后,项目可以顺利运行。
@grandsong 是的,脚手架最新版本已经处理这个问题了