How to import ipcRenderer in react?

Tags: , , , ,



I’ve tried to import ipcRenderer in react app

import {ipcRenderer} from 'electron';

but I get this error message : require is not defined

Answer

You need to use

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

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

You can checkout this thread for a better explanation:

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



Source: stackoverflow