尝试运行电子应用程序时找不到模块应用程序

时间:2016-09-25 03:41:49

标签: javascript node.js electron

我已经看到了关于此的其他问题,但它不一样。

Windows 7 x64 节点6.6.0 电子1.4.1 npm 3.19.8

我的问题是,如果我运行npm start调用我的package.json中定义的electron .,那么该应用运行正常。但是,如果我只是尝试运行electron .,那么我会收到上述错误“无法找到模块应用”

我认为它必须与路径相关,但我无法弄明白。 npm start正在运行相同的命令,我在main.js所在的根文件夹中运行这两个命令。我也尝试使用相同的错误明确调用electron main.js

另一个注意事项:当我使用Phpstorm运行调试会话时,它运行成功。调试配置,Node interpreter = electron.cmd和Javascript File = main.js

按要求

package.json

{
  "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 个答案:

答案 0 :(得分:0)

我做了以下更改以解决此问题:

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

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