Using node.js require in eel
See original GitHub issueHello,
I am having some errors in my electron app that I believe are due to how eel deals with electron. My problems are that when I try and create my own minimise and close buttons, it says
Uncaught ReferenceError: require is not defined at index.html:137
and
Uncaught ReferenceError: require is not defined at initNodeRequire (index.js:123) at index.js:109
when the page is loaded,
then
Uncaught ReferenceError: BrowserWindow is not defined at window_minimise (index.js:113) at HTMLButtonElement.onclick (index.html:18)
when I click minimise.
I go into more detail here, and I have adapted my JS file to use the code in the answer suggested, except I removed the {} around BrowserWindow.
I tested this function without eel by changing mainWindow.loadURL('http://localhost:8000/html/index.html')
to mainWindow.loadFile('web/html/index.html')
and starting it with npm start
. Then it worked.
I believe the issue is that node features such as require
do not run in the browser, and since this is retrieving a webpage from the browser it causes the error.
Do you know any way that this can be resolved?
Thanks.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Top GitHub Comments
@04fsnape Can you try the new example I just pushed and see if it works?
Press ctrl+shift+i to open dev control, then in the JS control - you should have either
require
ornodeRequire
defined (depending on which Eel version you have).Here is a script for minimizing, maximizing, and closing: