…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!