Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Electron app.on('ready'... never being called and electron window never showing. Seemingly tied to specific Git repository

Summary

I'm new to Electron development, and helping to lead a small project at work creating an electron application. After working inside the Git repository for a day or so, the electron window suddenly stopped appearing. I've determined that the function callback I give in app.on('ready' callback) is never being called.

My workstation setup: NodeJS version: 12.9.0 (Also tested with 10.16.3) Yarn Version: 1.17.3 OS: Windows 10 Enterprise

Originally, I was loosely following Ryan Brockhoff's Medium post about using Electron with React when electron started malfunctioning, but I've since cut a brand new Git branch and set up only an extremely minimal Electron project, and the same problem appears.

Electron does not malfunction the same way system-wide. I'm able to run the electron-api-demos perfectly. In addition, an older test directory where I was experimenting with electron still functions.

When I attempt to run the broken electron repository, Task Manager does show three electron processes as children under the command line process. When I run a well-functioning electron process, the electron process is shown as a parent process

I confirmed the 'ready' callback function is never being called through placing console.log statements inside the function, as well as a print statement when the callback is being assigned. the callback assignment print statement is being reached, and I can see the output on the console, but the print statement inside the callback function is never being reached, and that output is never being printed to the console.

Troubleshooting

I've done many troubleshooting steps at this point:

Troubleshooting: I deleted and re-cloned the Git repository elsewhere on my computer Result: problem persists

Troubleshooting: Let the program run for a while, maybe it needs to set something up before it's ready Result: After 10+ minutes, no change

Troubleshooting: I downloaded the electron-api-demos repository to see if electron worked in that project Result: electron-api-demos works perfectly as expected

Troubleshooting: I downgraded my electron version from "^6.0.3" to "^6.0.1", which works on a different project on my computer Result: problem persists

Troubleshooting: I created a new empty Git branch, with no code and attempted to create a new minimal electron project in the same git repository I had been seeing the problem in Result: problem re-emerges

Troubleshooting: Completely re-installed Node JS, changing versions from 12.x latest to 10.x LTS Result: no change

Troubleshooting: cloned and attempted to run the project inside an Ubuntu Virtual Machine Result: Success, project works as expected

Troubleshooting: Asked Co-worker to install project on their Windows 10 machine Result: Success, co-worker could not re-produce my issue

Code

I set up an extremely minimal project to re-produce this issue. The following is my current project:

package.json

{
  ...
  "main": "main.js",
  "scripts": {
    "electron-start": "electron ."
  },
  "devDependencies": {
    "electron": "^6.0.3"
  },
  ...
}

main.js

const {app, BrowserWindow} = require('electron')      

function createWindow () {
  console.log("inside the on ready callback"); //for troubleshooting
  win = new BrowserWindow({width: 800, height: 600})  
  win.loadFile('index.html')   
}      

console.log("outside the function"); //for troubleshooting
app.on('ready', createWindow)

index.html

<!DOCTYPE html>
<html lang="en">
  <body>
    <h1>Hello World!</h1>
  </body>
</html>

When I run yarn electron-start, the following prints out to my console:

yarn run v1.17.3
$ electron .

 outside the function

The print statement for inside the on ready callback is never reached. No errors are being emitted.

Conclusion

At this point, my suspicion is that there is something on my computer that is messed up. The Git repository that this code runs inside seems to be causing problems as well. I've done a lot of googling and I can't find anyone else facing this problem. The only thing I can think from here is to try scrapping our entire git repository and creating a new one (which may or may not be possible), and taking my computer into tech support for a possible replacement. Any clues on how to move forward would be greatly appreciated. Thanks

like image 617
user309775 Avatar asked Aug 22 '19 17:08

user309775


People also ask

How do you close the electron window?

addEventListener("click", function (e) { var window = remote. getCurrentWindow(); window. close(); });

How do you create an electron window?

Windows can be created from the renderer in two ways: clicking on links or submitting forms adorned with target=_blank. JavaScript calling window. open()

How can you tell if an app is an electron?

If you see an app. asar file, or something similar with the . asar suffix, it is most likely an Electron App. Windows: Open up the program files directory of the application you are wondering about, and check the file folder for any file with .


2 Answers

Workaround: Call app.removeAllListeners('ready') before app.on('ready', createWindow)

like image 157
Oleks Avatar answered Nov 15 '22 18:11

Oleks


Alright, so I eventually did find a solution to this. This error was caused by attempting to install extra devtools using electron-devtools-installer. I found that the error was caused by data being left over in the %AppData%/electron directory, and the %AppData%/[projectname] directory. Deleting these two directories solves this issue.

like image 24
user309775 Avatar answered Nov 15 '22 19:11

user309775