简体   繁体   English

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

[英]Cannot find module app when trying to run electron app

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 Windows 7 x64 节点 6.6.0 电子 1.4.1 npm 3.19.8

My problem is that if I run npm start which calls electron .我的问题是,如果我运行npm start调用electron . defined in my package.json the app runs fine.在我的 package.json 中定义的应用程序运行良好。 However if I just try to run electron .但是,如果我只是尝试运行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. npm start正在运行相同的命令,我在 main.js 所在的根文件夹中运行这两个命令。 I have also tried explicitly calling electron main.js with the same error.我也试过用同样的错误显式调用electron main.js

Another note: when I run a debug session using Phpstorm it runs successfully.另一个注意事项:当我使用 Phpstorm 运行调试会话时,它运行成功。 The debug configuration, Node interpreter = electron.cmd and Javascript File = main.js调试配置,Node interpreter = electron.cmd 和 Javascript File = main.js

package.json as requested 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');

    });
})();

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
    })
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM