electronnsiselectron-builderasar

Electron nsis Installer x 64 not including node_modules?


I have an electron app that runs very smoothly both in dev and prod envs. I'm having issues with packaging a windows installer.

Here's what I'm doing.

$ npm install

-> Postinstall will take care of installing native production dependencies.

$ npm run prod-build

My output folder structure is :

--win-unpacked
  --locales 
  -- resources
     --app.asar.unpacked
       --node_modules
         **--node-datetime** ( no other node module is included)
     --app
     --electron
     --elevate
  ...
--Some App Setup 1.0.0 .exe

Electron-builder generates an .exe file that I successfully install. The app launches but nothing loads. Any idea where I should start?

Package.json

 {
      "name": "Some App",
      "version": "1.0.0",
      "license": "MIT",
      "main": "./src/app.js",
      "scripts": {
        "ng": "ng",
        "start": "ng serve --proxy-config proxy.conf.json",

      "build": 
              "productName": "Some Product",
              "win": {
              "description": "Some Desc",
              "author": "Me",
              "target": "nsis",
              "arch": [
                "x64"
              ]
            }
          }, 

 "test": "ng serve --proxy-config proxy.conf.json && electron . ",
        "lint": "ng lint",
        "e2e": "ng e2e",
        "electron": "electron .",
        "postinstall": " electron-builder install-app-deps",
        "dev-build": "ng build -prod --aot=false && electron . ",
        "prod-build": "ng build -prod --aot=false && electron-builder -w"
      },
      "private": true,
      "dependencies": {
        "@angular/animations": "^4.0.0",
        "@angular/common": "^4.0.0",
        "@angular/compiler": "^4.0.0",
        "@angular/core": "^4.0.0",
        "@angular/forms": "^4.0.0",
        "@angular/http": "^4.0.0",
        "@angular/platform-browser": "^4.0.0",
        "@angular/platform-browser-dynamic": "^4.0.0",
        "@angular/router": "^4.0.0",
        "@swimlane/ngx-charts": "^6.0.2",
        "@types/jspdf": "^1.1.31",
        "@types/underscore": "^1.8.3",
        "bluebird": "^3.5.0",
        "body-parser": "^1.18.2",
        "bootstrap": "^3.3.7",
        "bootstrap-notify": "^3.1.3",
        "chartist": "^0.11.0",
        "core-js": "^2.4.1",
        "d3": "^4.10.2",
        "express": "^4.16.2",
        "jasmine-core": "~2.6.2",
        "jquery": "^3.2.1",
        "moment": "^2.21.0",
        "ng2-datepicker": "^1.8.3",
        "ng2-modal": "0.0.25",
        "ngx-modialog": "^3.0.4",
        "node-datetime": "^2.0.3",
        "rxjs": "^5.1.0",
        "sqlite3": "^4.0.0",
        "underscore": "^1.8.3",
        "zone.js": "^0.8.4"
      },
      "devDependencies": {
        "@angular/cli": "1.2.1",
        "@angular/compiler-cli": "^4.0.0",
        "@angular/language-service": "^4.0.0",
        "@types/electron": "^1.6.10",
        "@types/jasmine": "~2.5.53",
        "@types/jasminewd2": "~2.0.2",
        "@types/jquery": "^3.2.12",
        "@types/node": "~6.0.60",
        "codelyzer": "~3.0.1",
        "electron": "^1.8.4",
        "electron-builder": "^19.45.4",
        "electron-packager": "^9.1.0",
        "jasmine-spec-reporter": "~4.1.0",
        "karma": "~1.7.0",
        "karma-chrome-launcher": "~2.1.1",
        "karma-cli": "~1.0.1",
        "karma-coverage-istanbul-reporter": "^1.2.1",
        "karma-jasmine": "~1.1.0",
        "karma-jasmine-html-reporter": "^0.2.2",
        "protractor": "~5.1.2",
        "ts-node": "~3.0.4",
        "tslint": "~5.3.2",
        "typescript": "~2.3.3"
      },

added this to the bottom of my package.json instead of where it was before

      "build": {
        "win": {
          "target": "nsis"
        }
      }

}

app.js (entry point)

 const electron = require('electron');
    const express = require('express');
    const e_app = express();
    const bodyParser = require('body-parser');
    const path = require('path')
    const app = electron.app
    const BrowserWindow = electron.BrowserWindow;
    const url = require('url');
    const fs = require('fs');
    const os= require('os');
    const ipc = electron.ipcMain;
    const shell = electron.shell;
    const router = require('./electron/routes/req-router');
    const dateTime = require('node-datetime');
    let win
    let temp_win
    //set to true for production release
    function createWindow () {
      win = new BrowserWindow({width:1200,height:750,webPreferences: {webSecurity: false}})
      var serve_path = path.join('file://',__dirname,'/../build/index.html');
        win.loadURL(serve_path);
      win.on('closed', function () {
        win = null
      })

    }

Project Folder Structure

 --build
    --db
    --dist
    --e2e
    --node_modules
    --src
      --app
      --assets
      --electron
      --environemtns
       -app.js
       -index.html
       ...
    --typings

Solution

  • Installing electron-packager and referencing the packaged output when calling electron-build seems to do the trick.

    $ npm install --save-dev electron-packager@9.1.0 ( which happens to be the release version that doesn't error out on me"

    added the following script

    "pack": "electron-packager ."
    

    modified the prod-build script

    "prod-build": "ng build -prod --aot=false && electron-builder -w --prepackaged ./Some-App-win32-x64",