question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using node.js require in eel

See original GitHub issue

Hello,

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:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
ChrisKnottcommented, Jun 3, 2019

@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 or nodeRequire defined (depending on which Eel version you have).

0reactions
stafordtitusscommented, Aug 30, 2020

Here is a script for minimizing, maximizing, and closing:

const BrowserWindow = nodeRequire('electron').remote;

function window_minimize(){
    var window = BrowserWindow.getCurrentWindow();
    window.minimize();
}

function window_maximize(){
    var window = BrowserWindow.getCurrentWindow();
    if(!window.isMaximized()){
        window.maximize();
    }else{
        window.unmaximize();
    }
}

function window_close(){
    var window = BrowserWindow.getCurrentWindow();
    window.close();
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using node.js require in eel · Issue #147
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 ......
Read more >
Uncaught ReferenceError: require is not defined with EEL
join(__dirname, 'preload.js'), nodeIntegration: true, enableRemoteModule: true } }) // and load the index.html of the app. // mainWindow.
Read more >
eel
Easy. The eel module exports a function that logs at the "info" level: log = require('eel') version = require ...
Read more >
What is require?
js ') { message: 'hi', say: [Function] } node> require('./example.js').message = "hey" //set the message to "hey" 'hey' node ...
Read more >
Create HTML User Interface using Eel in Python
Eel is a Python library for making simple offline HTML/JS GUI apps, with full access to Python capabilities and libraries. Eel hosts a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found