Electronjs window.require 不是函数 [英] Electronjs window.require not a function

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

问题描述

我正在使用 create-react-app (react-scripts v3.0.0) 和 electronjs (v5.0.1).我正在尝试使用icpMain"模块将事件从渲染器传递到主进程如此处所述,但得到错误 window.require is not a function for line

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');

如何在渲染器进程中让 require 进入全局范围?或者是否有另一种方式在主进程和渲染器进程之间进行通信?

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?

我已经尝试完全删除 react 构建,并且只需使用 index.html 中的电子示例代码即可获得相同的结果.

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

推荐答案

好像加了偏好:

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

需要在渲染器进程中启用require.

is needed to enable require in the renderer process.

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

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