0

I had an Electron 5 environment running on Windows 7. Electron 5 was installed in the local node_modules. I was able to develop and run the application from VSCode.

I ran 'ncu' and opted to upgrade to Electron 7. This upgraded the electron (from 5.0.0 to 7.1.3) and socket.io modules (from 2.1.0 to 2.3.0). Now, when running 'electron .', my application starts but exits before the window is rendered. This is because I set the BrowserWindow to show:false and expose it on the ready-to-show event, which is never sent. I tried downgrading to Electron 5.0.12 but even after removing node_modules the behavior persisted.

I had a global instance of Electron 7 (7.0.0) but the application was using version 5 per a document.write(process.versions.electron) statement in my HTML. Regardless, I upgraded the global Electron version to 7.1.3 to match.

I then copied the electron-quick-start file, modified with numerous debug statements. The file is:

// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
const path = require('path')

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow

function createWindow () {
  // Create the browser window.
    console.log('READY:create...');
    mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  })

  // and load the index.html of the app.
  console.log('load index...');
  mainWindow.loadFile('index-none.html')

  // Open the DevTools.
  console.log('load devtools...');
  mainWindow.webContents.openDevTools()

  console.log('set handler...');
  // Emitted when the window is closed.
  mainWindow.on('closed', function () {
    console.log('MAINWIN:Closed...');
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null
  })
  console.log('created');
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', function () {
    console.log('onWall-close...');
  // On macOS it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') app.quit()
})

app.on('activate', function () {
    console.log('onActivate...');
    // On macOS it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (mainWindow === null) createWindow()
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
console.log('setting timer');
setTimeout(()=>{
    console.log('timing out...');
}, 15000)

console.log('setting timer2');
setTimeout(()=>{
    console.log('timing2 out...');
}, 200)
console.log('setting timer5');
setTimeout(()=>{
    console.log('timing5 out...');
}, 500)
console.log('setting timer7');
setTimeout(()=>{
    console.log('timing7 out...');
}, 700)
setTimeout(()=>{
    console.log('timing10 out...');
}, 1000)
setTimeout(()=>{
    console.log('timing12 out...');
}, 1200)
setTimeout(()=>{
    console.log('timing15 out...');
}, 1500)
setTimeout(()=>{
    console.log('timing17 out...');
}, 1700)

The HTML file is:

<html>
    <head><title>title</title></head>
    <body>
        Hello world.
    </body>
</html>

When I run either "electron eqs.js" or ".\node_modules.bin\electron.cmd eqs.js" I get this output:


 setting timer
setting timer2
setting timer5
setting timer7
READY:create...
load index...
load devtools...
set handler...
created
timing2 out...
timing5 out...
timing7 out...
timing10 out...
timing12 out...
timing15 out...

(Sometimes timing15 doesn't get printed).

In this case I see the BrowserWindow get created, but it remains blank. The developer tools do not open. Commenting out the line opening the developer tools changes nothing.

This behavior happens with both: C:\electron\electron-quick-start>.\node_modules.bin\electron.cmd -v

v5.0.12

C:\electron\electron-quick-start>electron -v

v7.1.3

I don't understand why the process is exiting while timers are active, so something somewhere must be calling app.exit() or similar. Besides "What is going on?", my obvious question is: how do I fix this?

rand'Chris
  • 788
  • 4
  • 17
  • sounds similar to [my current issue,](https://stackoverflow.com/q/59316390/7543162) which arose out of nowhere, although the electron window never even opens in my case... – oldboy Dec 29 '19 at 06:08
  • @oldboy, Thanks for the feedback but I think it's a very different problem. I've opened a bug report here: https://github.com/electron/electron/issues/21544 -- There is currently one additional external confirmation where Windows 10 works but not Windows 7. – rand'Chris Dec 31 '19 at 18:00
  • i figured mine out. somehow the value of the npm `ignore-scripts` configuration key changed to `true`, and wasnt resetting when i was uninstalling and reinstalling node. – oldboy Dec 31 '19 at 18:51

2 Answers2

0

I don't have an actual answer to this problem, but it was fixed when I upgraded to Electron 7.1.9 as I commented in the bug report https://github.com/electron/electron/issues/21544#issuecomment-577242668

During the upgrade some process took an unusually long time to complete but when it did my application ran successfully. I was also able to downgrade to a previous version of Electron and my application still ran, even when using a version that was failing earlier.

EDIT:

This problem resurfaced when an attempt to upgrade to Electron 8.2.2 failed because the application was running in a debugger. Unfortunately, no amount of version up/down-grades (up to 8.2.3) was able to recover the environment. Ultimately, disabling the sandboxing from my package.json launch script allowed me to proceed. This is the new command structure:

"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Electron: Main",
        "protocol": "inspector",
        "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
        "runtimeArgs": [
            "--remote-debugging-port=9223",
            "--no-sandbox",              <<<<<-- PASS THIS COMMAND OPTION
            "."
        ],
        "windows": {
            "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
        }
    },
    [...]
]
rand'Chris
  • 788
  • 4
  • 17
0

For anyone stumbling across this: I had a similar problem. Deleting the local files on Windows under %appdata%/YOUR_APP_NAME fixed Electron failing to launch properly for me.

Woww
  • 344
  • 2
  • 10