electron-builder: Error: Cannot find module ... app.asar/index.js

Successfully built my angular1 app as an electron app. I can run it using electron-prebuilt, however, when I launch the installed dmg, the app fails immediately.

Image contains error message:

image

my dev-level package.json:

{
    "name": "activity-frontend",
    "version": "1.1.1",
    "author": "Sante Kotturi",
    "description": "activity-frontend: An Ionic project",
    "dependencies": {
        "gulp": "^3.5.6",
        "gulp-concat": "^2.2.0",
        "gulp-minify-css": "^0.3.0",
        "gulp-rename": "^1.2.0",
        "gulp-sass": "^2.0.4"
    },
    "devDependencies": {
        "bower": "^1.3.3",
        "electron-builder": "^3.5.0",
        "electron-prebuilt": "^0.37.5",
        "gulp-util": "^2.2.14",
        "shelljs": "^0.3.0"
    },
    "scripts": {
        "electron": "electron www",
        "postinstall": "install-app-deps",
        "pack": "build",
        "dist": "build"
    },
    "build": {
        "osx": {
            "contents": [
                {
                    "x": 410,
                    "y": 220,
                    "type": "link",
                    "path": "/Applications"
                },
                {
                    "x": 130,
                    "y": 220,
                    "type": "file"
                }
            ]
        }
    }
}

my app-level package.json which specifies a main.js:

{
  "name"    : "activity-uploader",
  "version" : "0.0.1",
  "main"    : "main.js"
}

my main.js just in case it helps: [EDIT with correct main.js]

var app = require('app');  // Module to control application life.
var BrowserWindow = require('browser-window');  // Module to create native browser window.

// Report crashes to our server.
require('crash-reporter').start();

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is GCed.
var mainWindow = null;

// Quit when all windows are closed.
app.on('window-all-closed', function() {
  // On OS X it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform != 'darwin') {
    app.quit();
  }
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
  // Create the browser window.
  mainWindow = new BrowserWindow({width: 800, height: 700});

  // and load the index.html of the app.
  mainWindow.loadURL('file://' + __dirname + '/index.html');

  // Emitted when the window is closed.
  mainWindow.on('closed', function() {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;
  });
});

I launched Mac Finder > my app > Contents > Resources to see if app.asar was an inspectable but its a binary file: app.asar: application/octet-stream; charset=binary

Any help or pointing in the right directions of resources is much appreciated.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 20 (11 by maintainers)

Most upvoted comments

Try to set path as "main" : "./main.js"

I was having the "index.js" in the "app.asar" does not exist. Seems like a wrong configuration. error because my electron app is not in an app folder. So I added this to the package.json of the main repo (not the one of the app).

"directories": {
    "app": "./electron/"
}

Hope it helps someone.

@develar I’ve tried this, rebuilt and reinstalled the dmg but getting the same error. I’m not using any es6 or module system in my project, maybe that has something to do with it?

Wel… To ensure that it is not an asar issue, set build.asar: false (dev-level package.json in the existing build: asar: false)