Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Electron Uncaught ReferenceError: require is not defined 2021 even nodeIntegration is true

Posted on May 23, 2021May 23, 2021 by Habibie

This “require is not defined” is pretty annoying to me as Electron user.

Last year when I got this problem, I can simply solve it by adding: nodeIntegration: true.

But this time, on 2021, this problem comes again. So to solve it we need to add another thing here: contextIsolation: false.

I don’t know is it going to be a new game next year or what.

So, right now my main.js file to make my Electron program running is this:

const { ipcMain, app, BrowserWindow } = require('electron');
 
function createWindow () {
    const win = new BrowserWindow({
        width: 1280,
        height: 720,
        webPreferences: {
            nodeIntegration: true,
			contextIsolation: false,
            enableRemoteModule: true,
        }
    })
 
    win.loadFile('index.html');
    win.webContents.openDevTools();
	win.removeMenu();
     
}
 
app.whenReady().then(createWindow);
 
app.on('window-all-closed', () => {
    app.quit();
});
 
app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
        createWindow();
    }
})
 
ipcMain.on('quitprogram', (evt, arg) => {
    app.quit();
});
Post Views: 343
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger – Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme