electron-windows-autoupdate icon indicating copy to clipboard operation
electron-windows-autoupdate copied to clipboard

Uncaught ReferenceError: require is not defined

Open jalilzade opened this issue 8 years ago • 6 comments

Hi. i coped your index.html to my own index.html when trying to run electron app it says :

Uncaught ReferenceError: require is not defined

jalilzade avatar Feb 11 '17 14:02 jalilzade

heh, looks like you launch index.html in classical browser, not via electron.

vojtatranta avatar Feb 11 '17 14:02 vojtatranta

you got to use npm start script to run Electron which is a browser wrapped in C++, which has bridge to Node.js inside.

vojtatranta avatar Feb 11 '17 14:02 vojtatranta

No.i add your code to my index.html then build my app from npm. then make pack of my electron app then run electron app. i have mainWindow.webContents.openDevTools(); to see what happens behind.there is console error which says : Uncaught ReferenceError: require is not defined

jalilzade avatar Feb 11 '17 14:02 jalilzade

Maybe you did not allow node.js in the browser window, that's the only idea I have.

vojtatranta avatar Feb 11 '17 15:02 vojtatranta

enable nodeIntergration when creating the window

app.on('ready', () => {
    console.log('Hello from Electron.');
    mainWindow = new BrowserWindow({webPreferences: {
        nodeIntegration: true
      }});
    mainWindow.webContents.loadFile(path.join(__dirname,"index.html"));
    mainWindow.webContents.openDevTools();
});

sathiraumesh avatar Apr 29 '19 17:04 sathiraumesh

yup, good point @sathiraumesh

vojtatranta avatar Apr 21 '20 13:04 vojtatranta