How to use electron on Jhipster Angular generated application?

I just discovered electron and I found it interesting, so I want to implement it on my jhipster angular project (lastest jhipster version)

I tried following this tutorial and adapt it but I believe since Jhipster uses Webpack my build is not fine

here is what I have done

I declared a main.js file in src/main/webapp folder as below

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

let win;

function createWindow() {
  win = new BrowserWindow({ width: 800, height: 600 });

  // load the dist folder from Angular
      pathname: path.join(__dirname, `/dist/index.html`),
      protocol: "file:",
      slashes: true

  // The following is optional and will open the DevTools:
  // win.webContents.openDevTools()

  win.on("closed", () => {
    win = null;

app.on("ready", createWindow);

// on macOS, closing the window doesn't quit the app
app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {

// initialize the app's main window
app.on("activate", () => {
  if (win === null) {

Then I tried updating my config files as below


  "name": "boxing",
  "version": "0.0.1-SNAPSHOT",
  "main": "main.js", <-- added this
  "description": "Description for boxing",
  "private": true,
  "license": "UNLICENSED",
  "cacheDirectories": [
  "dependencies": {
    "@angular-devkit/build-angular": "^0.803.14", <-- installed using npm
  "scripts": {
    "electron": "ng build --base-href ./ && electron .",


  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "boxing": {
      "root": "",
      "sourceRoot": "src/main/webapp",
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "skipTests": true,
          "style": "scss"
        "@schematics/angular:directive": {
          "skipTests": true
        "@schematics/angular:guard": {
          "skipTests": true
        "@schematics/angular:pipe": {
          "skipTests": true
        "@schematics/angular:service": {
          "skipTests": true
      "prefix": "jhi",
      "architect": {
        <-- added this lines
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist"
       <-- end of add
  "defaultProject": "boxing",
  "cli": {
    "packageManager": "npm"

I updated finally my index.html href to ./

but when I run the command in terminal I m getting this error

npm run electron

[email protected] electron /home/housseyn/Desktop/projects/salle-de-sport ng build --base-href ./ && electron .

Schema validation failed with the following errors: Data path "" should have required property 'main'. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] electron: ng build --base-href ./ && electron . npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] electron script. npm ERR! This is probably not a problem with npm. There is likely additional logging output >above.

npm ERR! A complete log of this run can be found in: npm ERR! /home/housseyn/.npm/_logs/2019-10-25T16_00_19_675Z-debug.log



You have to build your project using this commande npm run electron-build after that you add it in a script to your package.json

check in this doc until the end

I hope that can help you,


Use this configuration :

          "name": "angular-electron-demo",
          "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",
            "start:electron": "ng build --base-href ./ && electron ."
          // [...]

After add this, you can use the start:electron script to execute the ng build --base-href ./ && electron . which first builds the project and then run electron from the current folder.

Go back to your terminal and run:

npm run start:electron


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.