- 更新:2021-03-18 09:52:18
- 首发:2021-03-18 09:44:46
- 教程
- 6351
在 Electron 12 及更高版本,设置了nodeIntegration: true
及nodeIntegrationInWorker: true
、nodeIntegrationInSubframes: true
,渲染进程仍然可能出现require is not defined
的报错。
这个报错还跟随有module is not defined
或exports is not defined
。
同样的报错在Electron 5+曾出现过,原因是发布v5.0.0
的时候,官方将nodeIntegration
默认值设置为了false
(与此同时还将webviewTag
设置为了false
)。
近期,Electron 12.0.0 发布。修复了诸多异常。同时也将contextIsolation
的默认值更改为true
(详见:https://github.com/electron/electron/pull/27949)。
官方特地将此默认值修改作为重大更改
。特地提示如下:
在Electron 12中,contextIsolation
默认情况下将启用。若要还原以前的行为,contextIsolation: false
必须在WebPreferences中指定。
我们建议启用contextIsolation以确保应用程序的安全。
另一个含义是,除非nodeIntegration
值为true
并且contextIsolation
值为false
,否则不能在渲染器过程中使用 require()
。
有关更多详细信息,请参见:github.com/electron/electron/issues/23506
webPreferences
API设置参考:https://www.electronjs.org/docs/api/browser-window
contextIsolation
设置的意思是是否开启上下文隔离
,意味着是否在独立 JavaScript 环境中运行 Electron API
和指定的preload
脚本。关于因此导致的上下文隔离
问题,参考:https://www.electronjs.org/docs/tutorial/context-isolation
也就是说,同时设置nodeIntegration: true
及contextIsolation: false
解决该问题!
找了好久,终于找到了新的解决办法。太感谢了
❤️
感谢回复! Clang 在生成时沿用了 GCC 的版本号标识,我是不是可以理解为Clang 18.1.4生成时使用的就是GCC4.8,所以我后续使用gcc 9.4
gcov
就会有不兼容的问题抱歉,这块我也不太清楚,尝试寻求AI的帮助吧。
我在这个过程中遇到了各种问题- -,现在在UDC core: g_serial: couldn't find an available UDC卡住了,请问大佬有什么解决方案吗,还是说我前置的设置就错了呢,> 这个需求很特殊。是可以的,但是比较困难,需要修改驱动配置。
好思路呀!!
关于hex编辑器,网上没找到特别好用的(小白没办法),最后在vscode上扩展一搜hex,第一个安装一下就可以用vscode进行hex编译了