keybraker / python-gui-electron

A simple example on how to create electron GUIs for python programs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught ReferenceError: require is not defined

datavectors opened this issue · comments

commented

I ran npm start and window was launched but links did not work.
Inspecting View > Toggle Developer Tools I read this error ..
Uncaught ReferenceError: require is not defined

Further digging around unearthed this explanation ..

stackoverflow forum

I modified main.js to add under var ui = new BrowserWindow({

webPreferences: {
nodeIntegration: true
 },

And after npm start no errors.

That solved it for me too 😀
I'm so glad that I postponed my tests with this repo. With my almost non-existent electron experience I wouldn't have figured that out.
Thanks.

PS: You might want to create a pull request for that.

indeed this fixes but author blocks new branches

I am working on an update as the example was made on version 1 and we are now at 11. What you propose is indeed a solution, but one that is prone to remote native code execution attacks.
There is a new way to implement you inclusion of javascript application, which is as follows:

webPreferences: {
    preload: path.join(__dirname, 'gui_example.js'),
    contextIsolation: true
}

I get the same error with electron 13.

I am also getting that error.