As the title says, I am getting this error again and again whenever I am trying to change the browserwindow: TypeError: Cannot read properties of undefined (reading 'on')
According to my previous question, I had a problem with the import/export. Now that I found about ipcRenderer, I used it but still got an error:
Here is my main.js (index.js)
const { app, BrowserWindow, ipcRenderer } = require("electron")
var mainWindow = null
app.on("ready", () => {
mainWindow = new BrowserWindow({
"width": 500,
"height": 500,
"webPreferences": {
"contextIsolation": false,
"nodeIntegration": true,
},
"opacity": 0.7,
})
mainWindow.loadFile("src/html/welcome.html")
})
ipcRenderer.on("update", (event, args) => {
mainWindow.loadFile("src/html/update.html")
})
And let's say this is my any js file:
const { ipcRenderer } = require("electron")
ipcRenderer.send("update")
After running the above code, I get an error. Now I comment out the ipcRenderer.on() line, the app works as expected.
If I'm not mistaken in your index.js file where you create the window you must declare ipcMain instead of ipcRenderer so here ipcRenderer.on("update", (event, args) => { mainWindow.loadFile("src/html/ update.html") }) you must change ipcRenderer to ipcMain