Skip to content
Advertisement

How to solve TypeError: Cannot read property ‘send’ of undefined in app.on

I have an error:

TypeError: Cannot read propety ‘send’ of undefind on start of my program. How to correctly trigger app.on without errors?

import * as electron from "electron";
const {app, BrowserWindow,ipcRenderer,ipcMain} = electron;

var correspondingWindow = null;
let mainWindow;

ipcMain.on('newWindow', function (e, category) {

//some code with switch Window_1
 
});

app.on('ready', function () {
  "use strict";
  ipcRenderer.send('newWindow', 'Window_1');
});

Advertisement

Answer

I feel like this is probably a dupe of another question, but ipcRenderer cannot be used in the main process. See the docs which say:

Process: Renderer

If you want to send a message from the main process to the main process, you can use ipcMain.emit, or just call the function directly. Why send messages in this case?

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement