电子 5.0.0 “未捕获的参考错误:未定义要求"

electron 5.0.0 quot;Uncaught ReferenceError: require is not definedquot;(电子 5.0.0 “未捕获的参考错误:未定义要求)
本文介绍了电子 5.0.0 “未捕获的参考错误:未定义要求"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我最初使用的是 electron stable (4.x.x),并且能够在我的浏览器和渲染器进程中使用 require.我升级到 electron beta (5.0.0) 因为我需要更新版本的节点并且在我的渲染器进程中遇到了这个错误消息,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.

推荐答案

适用于 Electron 12 及以上版本

For Electron version 12 and above

const electron = require("electron");

const { app, BrowserWindow } = electron;

app.on("ready", () => {
  const mainWindow = new BrowserWindow({
    width: 1000,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      enableRemoteModule: true,
    },
  });
  mainWindow.loadURL(`file://${__dirname}/index.html`);
});

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Google apps script get range of bytes from binary file(谷歌应用程序脚本从二进制文件中获取字节范围)
Sending Multiple attachments with Google Script from Google Drive(使用 Google 脚本从 Google Drive 发送多个附件)
Distributing Google Apps Scripts for Sheets in your company network(在您的公司网络中分发适用于表格的 Google Apps 脚本)
Upload file to my google drive from anyone using javascript(使用 javascript 将文件从任何人上传到我的谷歌驱动器)
quot;Shared Drivequot; support in Google Apps Script(“共享驱动器Google Apps 脚本中的支持)
Angular 2+ HTTP POST and GDrive API. Resumable file upload with name(Angular 2+ HTTP POST 和 GDrive API.带名称的可恢复文件上传)