2
votes

I have seen other questions about this but it is not the same.

Windows 7 x64 Node 6.6.0 electron 1.4.1 npm 3.19.8

My problem is that if I run npm start which calls electron . defined in my package.json the app runs fine. However if I just try to run electron . then I get the above error "Cannot find module app"

I think it must be path related but I can't figure it out. npm start is running the same command, I am running both commands in the root folder where main.js is located. I have also tried explicitly calling electron main.js with the same error.

Another note: when I run a debug session using Phpstorm it runs successfully. The debug configuration, Node interpreter = electron.cmd and Javascript File = main.js

package.json as requested

{
  "name": "demoelectronaureliamongodb",
  "title": "Demo Electron ES6, Aurelia MongoDB",
  "version": "1.0.0",
  "description": "Thick client demo app showing Electron, ES6, Aurelia, and MongoDB working together.",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "build-mac": "electron-packager . 'DemoElectronAureliaMongoDB' --platform=darwin --arch=x64 --version=0.35.1 --overwrite --out ./build/mac",
    "build-win": "electron-packager . 'DemoElectronAureliaMongoDB' --platform=win32 --arch=ia32 --version=0.35.1 --overwrite --out ./build/win"
  },
  "author": "",
  "homepage": "http://karlshifflett.wordpress.com",
  "license": "MIT",
  "keywords": [
    "electron",
    "aurelia",
    "es6",
    "mongodb"
  ],
  "repository": {
    "type": "git",
    "url": "https://github.com/Oceanware/demoelectronaureliamongodb.git"
  },
  "devDependencies": {
    "electron-packager": "^5.1.1",
    "electron-prebuilt": "^0.35.1"
  },
  "jspm": {
    "directories": {
      "baseURL": "src"
    },
    "dependencies": {
      "aurelia-bootstrapper": "npm:aurelia-bootstrapper@^1.0.0-beta.1",
      "aurelia-framework": "npm:aurelia-framework@^1.0.0-beta.1.0.2",
      "font-awesome": "npm:font-awesome@^4.4.0"
    },
    "devDependencies": {
      "babel": "npm:babel-core@^5.8.24",
      "babel-runtime": "npm:babel-runtime@^5.8.24",
      "core-js": "npm:core-js@^1.1.4"
    }
  }
}

main.js

(function () {
    /**
     * Main Electron process
     */

    'use strict';
    const electron = require('electron')
// Module to control application life.
    const app = electron.app
// Module to create native browser window.
    const BrowserWindow = electron.BrowserWindow


   // var app = require('app');
   // var BrowserWindow = require('browser-window');
    var applicationMenu = require('./browser/application-menu');

    var mainWindow = null;

    app.on('ready', function () {

        global.aureliaRoot = __dirname  + '/src/';

        applicationMenu.setup();

        mainWindow = new BrowserWindow({
            width: 900,
            height: 700,
            "min-width": 400,
            "min-height": 300,
            center: true,
            resizable: true
        });

        mainWindow.loadUrl('file://' + __dirname + '/src/index.html');

    });
})();
1
Can we see your package.json? - Andrew Li
You should probably update electron. - Andrew Li
I installed the latest "electron-packager": "^8.0.0", "electron-prebuilt": "^1.4.1". Now I get same error as stated when I run pm start as well as when I run electron . - dan
I got it working. I changed loudUrl to loadURL in main.js as it was deprecated. Then in menu file I changed app = require('app'); Menu = require('menu'); to const electron = require('electron'); const app = electron.app; Menu = electron.Menu; Would like to know why the new way works as I think the old way should still work - dan
@dan Those APIs were removed in Electron v1.0.0 - Vadim Macagon

1 Answers

0
votes

I did the below change to fix the issue:

const {app,BrowserWindow} =require('electron')

app.on('ready',function(){
    var mainWindow= new BrowserWindow({
        height:600,
        width:600
    })
})