am working with angular version 6.1.0 and electron 2.0,on running the app in browser it but on running npm run electron-build was successful but the app could not launch. thus, no browser window is displayed.
Here is the package.json
file:
{
"name": "front",
"version": "0.0.0",
"main": "main.js",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"electron": "electron .",
"electron-build":"ng build --prod"
}
...
}
Here is the main.js
file:
const {app, BrowserWindow} = require('electron');
let win;
function createWindow (){
win = new BrowserWindow({
height: 600,
width:600,
backgroundColor:'#ffffff'
})
win.loadURL(`file://${__dirname}/dist/index.html`)
win.on('closed',function(){
win=null;
})
}
app.on('ready',createWindow())
app.on('windows-all-closed',()=>{
if(process.platform!=='darwin'){
app.quit();
}
})
app.on('activate',function(){
if(win==null){
createWindow()
}
})
It's because you're calling the createWindow
function when the app first loads since in the ready event it thinks it should call the createWindow
function straight away since it has the two brackets at the end.
To fix it just take the brakets off so it becomes:
app.on('ready',createWindow)
Thanks to @KirkLarkin for spotting the bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With