TypeError: Cannot read property **** of undefined

I need help. This has eaten my time now for days. I have been facing issues with “TypeError: Cannot read property **** of undefined” while using sessions and dialogs. I believe the issue flows on to other APIs I haven’t needed just yet…

tryinging this
session.defaultSession.cookies.get({}) for example results to: “TypeError: Cannot read property ‘defaultSession’ of undefined”

hi, are you fixed it? I have the same problem

…I wouldn’t know of the best way to explain it; I got the fix but I am new to electron so getting the point across might have me not be so clear!

I will try explain with my project. I have the main file as start.js which requires yet another file main.js in a server folder: require('./server/main')

in these and only these two files can I use the packages from electron; having tried session and dialog so far. const { session, dialog } = require('electron') works perfectly.

in any other file, I presume the electron window is not being tapped (I lack a better term), so the only way to use this is to get the window as const { session, dialog} = window.require('electron')

you won’t get the error, but might as well get some other issues. My way around it has thus been to use IPC to communicate to this electron window. Its a long shot, but if I need a dialog for example, I get it through an IPC call to my main.js file… or any other file I may require in my main, which I call start.js as I mentioned earlier.

you can try window.require('electron') meanwhile, see where it gets you!