Electron.js window.require不是一个函数 [英] Electronjs window.require not a function

查看:1542
本文介绍了Electron.js window.require不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用create-react-app(反应脚本v3.0.0)和electronicjs(v5.0.1)。我正在尝试使用 icpMain模块将事件从渲染器传递到主流程,如此处所述, ,但出现错误 window.require 不是该行的功能

I'm using create-react-app (react-scripts v3.0.0) and electronjs (v5.0.1). I'm trying to pass events from the renderer to main process using the 'icpMain' module as described here, but get the error window.require is not a function for the line

const { ipcRenderer } = window.require('electron');

如何将需求引入全球渲染过程中的范围?还是在主进程与渲染进程之间存在另一种通信方式?

How can I get require into the global scope in the renderer process? Or is there another way of communicating between the main and renderer process?

编辑:

我试图完全去除反应生成物,仅使用电子就可以得到相同的结果index.html中的示例代码。

I've tried removing the react build entirely and get the same results simply using the electron example code in index.html.

推荐答案

看起来像在添加首选项:

It looks like adding the preference:

var mainWindow = new electron.BrowserWindow({
  ...
  webPreferences: {
    nodeIntegration: true,
  }
});

才能在渲染器中启用 require 过程。

is needed to enable require in the renderer process.

这篇关于Electron.js window.require不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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