【问题标题】:Electron,nodejs : App wont start, cannot find app in one of the modules.Electron,nodejs:应用程序无法启动,无法在其中一个模块中找到应用程序。
【发布时间】:2018-08-30 13:47:14
【问题描述】:

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

错误日志:

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

【问题讨论】:

  • require('app') 应该做什么?它是一个 npm 模块吗?还是其他地方的文件?
  • @evolutionxbox :我是新手,但据我所知,它在上面给出的 index.js 中。
  • var app = require('app') 这表示“我需要app”。从您所写的内容来看,它无处不在。
  • @evolutionxbox : 这是 index.js 中的第二行 : var app = require('app'),
  • According to the docs app 是 electron 的属性。所以你会有不同的要求,var electron = require('electron'); var app = electron.app

标签: javascript node.js npm electron


【解决方案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://www.electronjs.org/docs/tutorial/quick-start https://github.com/electron/electron-quick-start

【讨论】:

    猜你喜欢
    • 2015-02-19
    • 2018-12-11
    • 1970-01-01
    • 2019-09-09
    • 2020-10-15
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2021-05-12
    相关资源
    最近更新 更多