1

I just tried to test electron environment for programming with JavaScript on desktop with Windows 10.

So I have an app:

const electron=require("electron");
const app=electron.app;
const BrowserWindow=electron.BrowserWindow;

var mainWindow=null;

app.on("ready",function(){
  mainWindow=new BrowserWindow({height:600,width:800});
  mainWindow.loadURL("file://"+__dirname+"index.html");
});

and index.html is:

<html>
<head>
<title> MyIndex.html </title>
</head>
<body>
Hello World from Electron!<br>
</body>
</html>

and package.json is:

{
"name":"Electron-Test",
"version":"0.1.0",
"main":"./main.js",
"scripts":{"start":"electron ."}
}

If I run electron . or npm start the application seems to start, but no browser window opens. On console I have to press Ctrl-C to stop the application. Does anyone know where is the problem?

1 Answer 1

2

try to add one more/after file:
you are also missing a / before index.html

app.on("ready",function(){
  mainWindow=new BrowserWindow({height:600,width:800});
  mainWindow.loadURL("file:///"+__dirname+"/index.html");
});

i saw it in this video, at 3:32 https://www.youtube.com/watch?v=i0AkgNv4U4E

1
  • Ok, I started the script at another computer (win7). Your right, there is a slash missing. My problem with the windows 10 installation is, that now window opens at all, i.e. also not an empty window. On my windows 7 machine all works well. Apr 3, 2017 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.