Ok, so I'm trying to update a two year old Electron app to function. I needed to change out the syntax and remove window.require() and replace it with CreateBrowserWindow in order to get the app to render in a new window rather than in the browser at localhost:3000. While npm start creates a new window I keep getting a blank screen and the warning Electron could not be found. No hard resets for you!
I am able to get into the createWindow function but the app is starting without recognizing electron. Not sure how to go about making this work. Haven't been able to find anything using GoogleFu. Below is the code at the start of electron.js in my public folder (I've tried moving it out of public to the root folder but it makes no difference):
const { app, BrowserWindow, Menu, dialog } = require('electron');
const createWindow = () => {
const win = new BrowserWindow({
width: 800, height: 600, webPreferences: {
nodeIntegration: true, contextIsolation: false }
})
console.log('error')
win.loadFile('./index.html');
};
app.whenReady().then(() => { createWindow() })
When I run it I get this output:
Electron could not be found. No hard resets for you!
then line break
error
The problem is occurring at the outset. How do I direct my app to find electron?
- Upgrading to Electron v22
- Removing window.require() syntax and replacing it with BrowserWindow. Then expected app to open in new window. Got new window to open but no content in window.
- Putting a try catch block in the createWindow function to get a more detailed explanation of error. Got nothing, createWindow function still ran. Realized the error occurs before even getting there. Not sure why this works while getting the initial warning that Electron is not found. Doesn't that function rely on BrowserWindow, which is from the require(
electron
) statement. - Changing start script to
electron .
CodePudding user response:
Have you tried removing
require('electron-reload')(_dirname)
so you don't run electro-reload on development environment?