I am building a desktop application using Electron.js as the frontend and Python as the backend.
When i click a button, it’s meant to open a new window but I keep getting the error below:
mainWin.js:3 Uncaught TypeError: Cannot read property ‘BrowserWindow’ of undefined
I am stuck. please any advice?
My main process (index.js) is below:
//creating the app property
const { app, BrowserWindow, Menu } = require('electron')
const path = require('path');
function createWindow () {
// Create the browser window.
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
// and load the index.html of the app.
win.loadFile('ParentWin/Winindex.html')
// Open the DevTools.
win.webContents.openDevTools()
var menu = Menu.buildFromTemplate([{
label: 'Menu',
submenu: [
{label: 'Check for Update'},
{label: 'Adjust Notification Value'},
{
type:'separator'
},
{
label: 'Exit',
click() {
app.quit()
}
}]
},
{label: 'Tools',
submenu:[
{label:'Reload'}
]}
])
Menu.setApplicationMenu(menu);
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(createWindow)
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
while the parent window (mainWin.js) is below:
const electron = require('electron')
const path = require('path')
const BrowserWindow = electron.remote.BrowserWindow;
const submit = document.getElementById('submit_button')
submit.addEventListener('click', function(event) {
const modalPath = path.join('DCN/dc.html')
let win = new BrowserWindow({ frame: true, transparent: false, alwaysOnTop: true, width: 400, height: 200})
win.on('close', function() { win = null })
win.loadFile(modalPath)
win.show()
})