【发布时间】: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