Electron app shows blank screen when built with electron-builder
11:59 28 Jan 2020

As the title explains, i have a simple Electron app that loads a html page when started. Everything works fine, but if i try to build the project using electron-builder (yarn dist), the application shows nothing but a blank screen. Any idea of why this happens?

My project structure is the following:

-- e2e
-- dist
-- node_modules
-- src
   -- app
   -- assets
   -- environments
   -- index.html
-- editor.config
-- angular.json
-- broswerlist
-- karma.conf.js
-- main.js
-- package.json
-- package-lock.json
-- tsconfig.json
-- tslint.json

I also post my main.js and package.json files:

main.js

const electron = require("electron")
const {app, Menu, BrowserWindow} = require("electron")
const path = require("path")

let mainWindow

app.on('window-all-closed', e => e.preventDefault() )
app.on('ready', createWindow);

function createWindow() {

  mainWindow = new BrowserWindow({
    width:1380,
    frame:false,
    closable: false,
    minimizable: false,
    maximizable: false,
    resizable: false,
    autoHideMenuBar: true,
    webPreferences: {
      nodeIntegration: true
    }
  })


  mainWindow.webContents.openDevTools();


  mainWindow.loadURL(url.format({
    pathname: path.join(__dirname, 'dist/index.html'),
    protocol: "file",
    slashes: "true"
  }))

}

package.json

{
  "name": "test_app",
  "version": "1.0.0",
  "description": "test",
  "author": "me",
  "main": "main.js",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "electron": "electron .",
    "dist": "electron-builder",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "devDependencies": {
    "electron": "7.1.8",
    "electron-builder": "^22.2.0"
  },
  "build": {
    "target": [
      "nsis"
    ]
  },
  "dependencies": {
    "msal-electron-poc": "^0.1.0",
    "@angular-devkit/build-angular": "~0.803.21",
    "@angular/animations": "~8.2.14",
    "@angular/cli": "~8.3.21",
    "@angular/common": "~8.2.14",
    "@angular/compiler": "~8.2.14",
    "@angular/compiler-cli": "~8.2.14",
    "@angular/core": "~8.2.14",
    "@angular/forms": "~8.2.14",
    "@angular/language-service": "~8.2.14",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "fs": "0.0.1-security",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "rxjs": "~6.4.0",
    "ts-node": "~7.0.0",
    "tslib": "^1.10.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3",
    "zone.js": "~0.9.1"
  }
}
electron electron-builder