'Electron Uncaught Error: Cannot read properties of undefined (reading 'getAllWindows')

I tried getting the length of the windows availabale in my electron application using BrowserWindow in my preload.js file.

But it gives me an error saying

Uncaught Error: Cannot read properties of undefined (reading 'getAllWindows')

This is my code:

const{ipcRenderer,contextBridge,BrowserWindow} = require("electron")
console.log(BrowserWindow.getAllWindows().length)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source