Electron 12+ 出现 require is not defined 报错解决

在 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)。

内容来自 轶哥博客,版权归原作者所有。

阅读原文 ↗

把喜欢的内容,留在你的新标签页。

打开我的订阅