gpt4 book ai didi

Electronjs window.require 不是函数

转载 作者:行者123 更新时间:2023-12-03 12:20:09 26 4
gpt4 key购买 nike

我正在使用 create-react-app (react-scripts v3.0.0) 和 electronjs (v5.0.1)。我正在尝试使用“icpMain”模块将事件从渲染器传递到主进程 as described here ,但得到错误 window.require不是该行的函数

const { ipcRenderer } = window.require('electron');

我怎样才能得到 require进入渲染器进程的全局范围?或者是否有另一种方式在主进程和渲染器进程之间进行通信?

编辑:

我已经尝试完全删除 react 构建,只需使用 index.html 中的 Electron 示例代码即可获得相同的结果。

最佳答案

由于 Electron 12,默认启用 contextIsolation,这意味着 require() 不能在渲染器进程中使用,除非 contextIsolation 为 false,此链接中的更多信息 https://www.electronjs.org/docs/breaking-changes#default-changed-contextisolation-defaults-to-true
所以包括以下内容:

webPreferences: {
nodeIntegration: true,
contextIsolation: false,
}

关于Electronjs window.require 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56265958/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com