Evening,
I\'m looking into using electron to package an existing angular2 build. I thought I had a dry run working but the actual packaging seems to be failing (see fina
I had the same problem. This worked for me
// and load the index.html of the app.
window.loadURL(url.format({
pathname: path.join(__dirname, 'dist/index.html'), // important
protocol: 'file:',
slashes: true,
// baseUrl: 'dist'
}));
this works for me on linux
newWindow.loadFile(`${__dirname}/index.html`);
you can add this to view the directory of your main.js and from there navigate to the index.html.
console.log(__dirname)
I had the exact problem when i tried to build my app with electron-builder...
What worked for me was in package.json file i built with ng build then runed electron-builder
"scripts": {
...
"build-installer": "ng build --prod && electron-builder"
},
and in the index.html changed base href to
<base href="">
Problem may be the invalid path in main.js
, correct it if necessary
Just change the BrowserWindow' options:
new BrowserWindow({
webPreferences: {
webSecurity: false
}
})
If window's url points to a remote source, like http://..., browser will not allow to load local resource, unless you set the options above.
I had the same issue and my mistake was the win.loadURL
was not correct (loadURL tried to load a file who doesn't exist).
Be sure your url is correct otherwise you will get an error.