ArcherGu / fast-vite-nestjs-electron

Vite + Vue + Electron + Nestjs with esbuild, crazy fast! ⚡

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

contextisolation和require冲突怎么解决呀

veryws opened this issue · comments

微信截图_20220722124609

webPreferences: {
nodeIntegration: true,
contextIsolation: true,
preload: join(__dirname, '../preload/index.js'),
devTools: isDev
}
contextIsolation设为true
开发版本:界面正常,可调用IPC方法,但不用使用require方法
发布版本:界面空白

contextIsolation设为false
开发版本:界面正常,不可调用IPC方法
发布版本:界面正常,不可调用IPC方法

请问怎么解决这个问题呀

contextIsolation 开启后 electron 就会认为 require 不可用了,所以你开启后就要在前端检查下是否还在调用require。而且此时 nodeIntegration: true 也没有什么意义了。

contextIsolation 开启后主进程提供的接口应该通过 preload 进行暴露。

前端没用require,import也算嘛。请问在哪里修改呀
789
101
image

你的前端部分有 import { ipcRenderer } from 'electron' 这样的引入,你的前端应该是和 electron 完全隔离的,所以不要直接从 electron 中引入东西。