electron-vite icon indicating copy to clipboard operation
electron-vite copied to clipboard

不支持Electron 20吗

Open joyexpr opened this issue 3 years ago • 3 comments

Describe the bug

蛮尝试了下升级electron到20.1.2,发现模板(vue, ts) 跑不起来(下图),是目前还不支持20吗?还是有其它相关依赖需要同时升级?

另外我也蛮试了下降级electron到18,是正常的,请问目前支持的electron有明确的版本范围吗?

WeChat66ee82bd074b0b518b0f7cb4737c36cb

Electron-Vite Version

1.0.7

Electron Version

20.1.2

Vite Version

3.0.9

Validations

joyexpr avatar Sep 08 '22 11:09 joyexpr

Electron 20 应该开启了一些新特性,待我测试一下

alex8088 avatar Sep 08 '22 11:09 alex8088

@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依赖,所以可以)

后续会更新脚手架,更改这些配置

alex8088 avatar Sep 09 '22 04:09 alex8088

了解了,感谢 [强]

joyexpr avatar Sep 09 '22 06:09 joyexpr

我刚刚用 pnpm create @quick-start/electron 创建了新项目,并手动把依赖的 electron 版本升级到了最新的 20 。然后,项目可以顺利运行。

grandsong avatar Sep 17 '22 12:09 grandsong

@grandsong 是的,脚手架最新版本已经处理这个问题了

alex8088 avatar Sep 17 '22 12:09 alex8088