如何在反应中导入 ipcRenderer? [英] How to import ipcRenderer in react?

查看:50
本文介绍了如何在反应中导入 ipcRenderer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 react 应用程序中导入 ipcRenderer

I've tried to import ipcRenderer in react app

import {ipcRenderer} from 'electron';

但我收到此错误消息:require is not defined

but I get this error message : require is not defined

推荐答案

需要使用

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

否则它会尝试从 Webpack 或您使用的任何模块打包器导入它.

Otherwise it will try to import it from Webpack or whatever module bundler you use.

您可以查看此线程以获得更好的解释:

You can checkout this thread for a better explanation:

https://github.com/electron/electron/issues/7300

这篇关于如何在反应中导入 ipcRenderer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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