sindresorhus / electron-is-dev

Check if Electron is running in development
MIT License
426 stars 34 forks source link

Error [ERR_REQUIRE_ESM]: require() ..... index.js not supported #34

Closed SumitDerbi closed 8 months ago

SumitDerbi commented 8 months ago

while using this code getting following issue App threw an error during load Error [ERR_REQUIRE_ESM]: require() of ES Module D:\project\node_modules\electron-is-dev\index.js from D:\ecosail\index.js not supported

here is my code of electron index.js const { app, BrowserWindow, Menu } = require('electron'); const path = require('path'); const isDev = require('electron-is-dev');

function createWindow() { const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true, // Consider using contextIsolation and preload instead webSecurity: false // to disable web security (consider enabling for production) } });

if (isDev) { console.log('Running in development'); } else { console.log('Running in production'); } win.loadURL("http://localhost:3000/"); //win.webContents.openDevTools(); }

app.on('ready', () => { const menu = Menu.buildFromTemplate([]); Menu.setApplicationMenu(menu); createWindow(); });

app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } });

app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } }); Screenshot (17)

sindresorhus commented 8 months ago

https://github.com/sindresorhus/electron-is-dev/releases/tag/v3.0.0

kmturley commented 3 months ago

My project can't use ESM due to some dependencies. I am using an older version of this project which supports CommonJS npm install electron-is-dev@2