惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Recent Commits to openclaw:main
Recent Commits to openclaw:main
H
Heimdal Security Blog
SecWiki News
SecWiki News
H
Hacker News: Front Page
N
News | PayPal Newsroom
L
LINUX DO - 最新话题
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
AI
AI
C
Cybersecurity and Infrastructure Security Agency CISA
Scott Helme
Scott Helme
PCI Perspectives
PCI Perspectives
S
Securelist
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Cyberwarzone
Cyberwarzone
A
Arctic Wolf
Forbes - Security
Forbes - Security
T
Tor Project blog
Spread Privacy
Spread Privacy
WordPress大学
WordPress大学
I
Intezer
Martin Fowler
Martin Fowler
Help Net Security
Help Net Security
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Cisco Talos Blog
Cisco Talos Blog
Latest news
Latest news
博客园 - 司徒正美
W
WeLiveSecurity
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
V2EX
P
Palo Alto Networks Blog
Google DeepMind News
Google DeepMind News
IT之家
IT之家
阮一峰的网络日志
阮一峰的网络日志
V
Vulnerabilities – Threatpost
Jina AI
Jina AI
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
Simon Willison's Weblog
Simon Willison's Weblog
Project Zero
Project Zero
T
Threatpost
P
Privacy International News Feed
人人都是产品经理
人人都是产品经理
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - Franky
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research

轶哥博客

blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog
blog
2021-03-18 · via 轶哥博客

在 Electron 12 及更高版本,设置了nodeIntegration: truenodeIntegrationInWorker: truenodeIntegrationInSubframes: true,渲染进程仍然可能出现require is not defined的报错。

这个报错还跟随有module is not definedexports 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: truecontextIsolation: false解决该问题!