question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to require or import ipcRenderer

See original GitHub issue

Preflight Checklist

  • [ ✓ ] I have read the contribution documentation for this project.
  • [ ✓ ] I agree to follow the code of conduct that this project follows, as appropriate.
  • [ ✓ ] I have searched the issue tracker for a bug that matches the one I want to file, without success.

Issue Details

  • Electron Forge Version: 6.0.0-beta.57
  • Electron Version: 13.1.4
  • Operating System: macOS 11.4 (20F71) Big Sur
  • Last Known Working Electron Forge version:: N / A

Expected Behavior

I should be able to import or require ipcRenderer from electron in the Render process.

Screen Shot 2021-07-07 at 12 15 54 AM

renderer.ts

const { ipcRenderer } = require('electron')

Actual Behavior

Electron app window opens but crashes on the “⠸ Compiling Renderer Code” step.

Error

⠸ Compiling Renderer Code
An unhandled rejection has occurred inside Forge:
TypeError: Cannot set property 'native_modules/dist/Electron.app/Contents/Frameworks/Mantle.framework/Mantle' of undefined

To Reproduce

Create project with electron forge

npx create-electron-app my-new-app --template=typescript-webpack

Add ipcRenderer to renderer.ts

const { ipcRenderer } = require('electron')

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
acupofjosecommented, Jul 7, 2021

I have this same issue, a solution (though I hope it is only temporary) is to do the following:

 mainWindow = new BrowserWindow({
    // ...
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
    },
   // ...
  })

and to include on renderer code using:

const { ipcRenderer } = window.require('electron')
2reactions
rsathishtechitcommented, Jul 29, 2021

Another way of accessing ipcRenderer using ContextBridge API

https://github.com/electron-userland/electron-forge/issues/2160#issuecomment-889358025

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to require or import ipcRenderer · Issue #2362 - GitHub
I should be able to import or require ipcRenderer from electron in the Render process. Screen Shot 2021-07-07 at 12 15 54 AM....
Read more >
How to import the electron ipcRenderer in a react / webpack 2 ...
I fail to import or require ipcRenderer to make communication between main and renderer process possible. My setup can be found here: ...
Read more >
How to import ipcRenderer in Renderer Process' Component
You can do so with the following command. const ipcRenderer = window.require('electron').ipcRenderer;. While this is an easy way but it may ...
Read more >
can't resolve 'fs' in electron | The AI Search Engine You Control
First of all, I have been using electron.js on my client-side code and the I have been using const { ipcRenderer } =...
Read more >
Inter-Process Communication - Electron
Use the ipcMain and ipcRenderer modules to communicate between Electron ... you should be familiar with the idea of using a preload script...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found