电子5.0.0“未捕获的ReferenceError:未定义要求". [英] electron 5.0.0 "Uncaught ReferenceError: require is not defined"

查看:82
本文介绍了电子5.0.0“未捕获的ReferenceError:未定义要求".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初使用电子稳定(4.x.x),并且能够在我的浏览器和渲染器过程中使用require.我升级到了beta电子版(5.0.0),因为我需要较新版本的node并在渲染器进程Uncaught ReferenceError: require is not defined中遇到此错误消息.

I had initially been using electron stable (4.x.x), and was able to use require in both my browser and renderer processes. I upgraded to electron beta (5.0.0) because I needed a newer version of node and encountered this error message in my renderer process, Uncaught ReferenceError: require is not defined.

在谷歌上浏览并查看电子文档,我发现有评论说该错误可能是由于在初始化BrowserWindow时将webPreferences.nodeIntegration设置为false引起的;例如:new BrowserWindow({width, height, webPreferences: {nodeIntegration: false}});.但是我没有这样做,所以我认为还有其他问题,并继续寻求解决方案.

Googling and looking through the electron docs, I found comments saying the error could be caused by setting webPreferences.nodeIntegration to false when initializing the BrowserWindow; e.g.: new BrowserWindow({width, height, webPreferences: {nodeIntegration: false}});. But I was not doing this, so I thought something else must be the issue and continued searching for a resolution.

推荐答案

事实证明,nodeIntegration在以前的电子版本中默认为true,但在5.0.0中默认为false.因此,将其设置为true解决了我的问题.找不到在评论或电子页面上在线记录的更改,我想我应该做一个自我答复的SO帖子,以便将来遇到此问题的人更容易找到.

It turns out, nodeIntegration was true by default in previous electron versions, but false by default in 5.0.0. Consequently, setting it to true resolved my issue. Not finding this change documented online in comments or on electrons page, I thought I'd make this self-answered SO post to make it easier to find for future people who encounter this issue.

这篇关于电子5.0.0“未捕获的ReferenceError:未定义要求".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆