I have an error:
TypeError: Cannot read propety ‘send’ of undefind on start of my program. How to correctly trigger app.on without errors?
JavaScript
x
17
17
1
import * as electron from "electron";
2
const {app, BrowserWindow,ipcRenderer,ipcMain} = electron;
3
4
var correspondingWindow = null;
5
let mainWindow;
6
7
ipcMain.on('newWindow', function (e, category) {
8
9
//some code with switch Window_1
10
11
});
12
13
app.on('ready', function () {
14
"use strict";
15
ipcRenderer.send('newWindow', 'Window_1');
16
});
17
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?