Search code examples
reactjselectronjsxipctsx

window.require is not a function


my code:

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

enter image description here

Error:

TypeError: window.require is not a function

enter image description here


I tried to use IPC communication to control the Electron window via React.

However, the error 'TypeError: window.require is not function' continues.

Setting 'node integration' to true also results in an error. enter image description here

Is there a sure way to fix this error?

Also, is there a way to control the Electron window with React without using IPC communication?


Solution

  • Renderer process or not, require() is a NodeJS function to import external modules into your file, it is not something that will be on the window object.

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

    Keep in mind that your current configuration is completely insecure, and you should really consider using IPC with a preload file.