电子,nodejs:应用程序无法启动,无法在其中一个模块中找到应用程序。

时间:2018-03-21 12:28:03

标签: javascript node.js npm electron

我正在尝试一个应该指向我们网站的电子应用程序,所以我正在尝试其中一个教程..不幸的是,当我启动应用程序时,我收到以下错误:

错误日志:

akshay@akshay-mint-desktop ~/electron_tutorial_one $ npm start

> electron_tutorial_one@1.0.0 start /home/akshay/electron_tutorial_one
> electron .

App threw an error during load
Error: Cannot find module 'app'
    at Module._resolveFilename (module.js:455:15)
    at Function.Module._resolveFilename (/home/akshay/electron_tutorial_one/node_modules/electron-prebuilt/dist/resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.Module._load (module.js:403:25)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/akshay/electron_tutorial_one/index.js:2:11)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
A JavaScript error occurred in the main process
Uncaught Exception:
Error: Cannot find module 'app'
    at Module._resolveFilename (module.js:455:15)
    at Function.Module._resolveFilename (/home/akshay/electron_tutorial_one/node_modules/electron-prebuilt/dist/resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.Module._load (module.js:403:25)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/akshay/electron_tutorial_one/index.js:2:11)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
^Cakshay@akshay-mint-desktop ~/electron_tutorial_one $ 

index.js:

// Require the libraries used in the app
var app = require('app'),
    BrowserWindow = require('browser-window');

require('crash-reporter').start();

var mainWindow = null;

// Kill the app when all windows are closed
app.on('mainWindow-all-closed', function() {
  if (process.platform != 'darwin')
    app.quit();
});

app.on('ready', function() {
  // Create the main window for the app
  mainWindow = new BrowserWindow({
    "min-width"         : 800,
    "min-height"        : 600,
    fullscreen          : true,
    resizable           : true,
    "use-content-size"  : true
  });

  // Load in our content
  mainWindow.loadUrl('file://' + __dirname + '/index.html');

  // This is required for now due to https://github.com/atom/electron/issues/1117
  mainWindow.openDevTools();
  mainWindow.closeDevTools();

  // Ensure that garbage collection occurs when the window is closed
  mainWindow.on('closed', function() {
    mainWindow = null;
  });
});

package.json:

{
  "name": "electron_tutorial_one",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "electron ."
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "electron-prebuilt": "^1.4.13"
  }
}

1 个答案:

答案 0 :(得分:1)

而不是

// Require the libraries used in the app
var app = require('app'), BrowserWindow = require('browser-window');

你应该使用

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

你使用了一个非常古老的例子。电子模块是在两年前的0.35.0 'electron'下收集的;)

从发行说明:

  

添加包含所有公共API的电子模块。

您最好使用电子网站的教程:

https://electronjs.org/docs/tutorial/first-app

https://github.com/electron/electron-quick-start