Context: I have seen this question but it does not solve my issue.
When I try running my electron app, I receive no errors and it seems like it compiles, but the electron window does not pop up.
Response:
Date: 2019-05-08T03:02:22.036Z
Hash: 3303fd48d099a538493f
Time: 13840ms
chunk {0} runtime.26209474bfa8dc87a77c.js (runtime) 1.41 kB [entry]
[rendered]
chunk {1} es2015-polyfills.c5dd28b362270c767b34.js (es2015-polyfills)
56.4 kB [initial] [rendered]
chunk {2} main.8b6835f39caf5eafd09d.js (main) 276 kB [initial]
[rendered]
chunk {3} polyfills.8bbb231b43165d65d357.js (polyfills) 41 kB [initial]
[rendered]
chunk {4} styles.3ff695c00d717f2d2a11.css (styles) 0 bytes [initial]
[rendered]
^Seems like a completely normal response
Soon after, it exits without showing any error codes.
Main File:
const { app, BrowserWindow } = require ('electron')
let win;
function createWindow() {
//Create the browser window
win = new BrowserWindow({
width: 600,
height: 600,
backgroundColor: '#ffffff',
//icon: 'file:///' + __dirname + '/dist/assets/favicon.ico'
})
win.loadURL('file:///' + __dirname + '/index.html')
win.on('close', function() {
win = null
})
}
// Create window on electron intialization
app.on('ready', createWindow)
//Quit when all windows are closed
app.on('window-all-closed', function(){
// On macOS specific close process
if(process.platform !== 'darwin'){
app.quit()
}
})
app.on('activate', function(){
//macOS specific close process
if(win === null){
createWindow()
}
})
HTML File:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bot</title>
<base href="./">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
Package.json File:
{
"name": "shopify-bot",
"version": "0.0.0",
"license": "MIT",
"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"
},
"private": true,
"dependencies": {
"@angular/animations": "~7.2.0",
"@angular/common": "~7.2.0",
"@angular/compiler": "~7.2.0",
"@angular/core": "~7.2.0",
"@angular/forms": "~7.2.0",
"@angular/platform-browser": "~7.2.0",
"@angular/platform-browser-dynamic": "~7.2.0",
"@angular/router": "~7.2.0",
"core-js": "^2.5.4",
"node-html-parser": "^1.1.15",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.13.9",
"@angular/cli": "~7.3.8",
"@angular/compiler-cli": "~7.2.0",
"@angular/language-service": "~7.2.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.5.0",
"electron": "^5.0.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.2.2"
}
}
I’m pretty new to angular, so any help would be appreciated!
2
Answers
I figured out my error. I was essentially following a guide from this outdated YouTube video which lost support after Angular 4. I read and followed the instructions from this article and was finally able to open a window.
Try to replace your
win.loadURL
with:Two main points:
protocol: 'file:'
;