我今天开始使用电子,并按照指南创建一个简单的应用程序浏览器窗口,我在命令窗口中运行npm start,在我输入后显示了很多错误,我已经发布了下面的信息和我的代码。
控制台错误:
C:\Users\Administrator\Desktop\electron>npm start
> breef@1.0.0 start C:\Users\Administrator\Desktop\electron
> node index.js
module.js:471
throw err;
^
Error: Cannot find module 'app'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\Administrator\Desktop\electron\index.js:1:73)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.9.2
npm ERR! npm v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! breef@1.0.0 start: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the breef@1.0.0 start script 'node index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the breef package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs breef
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls breef
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\Administrator\Desktop\electron\npm-debug.log
这是我的package.json:
{
"name": "breef",
"version": "1.0.0",
"description": "A simple chat application.",
"main": "index.js",
"dependencies": {
"electron": "^1.4.12"
},
"devDependencies": {},
"scripts": {
"test": "breeftestcmd",
"start": "node index.js"
},
"keywords": [
"breef"
],
"author": "Sage & Sh4wn",
"license": "ISC"
}
这是我的index.js:
var app = require("app")
var browserWindow = require("browser-window")
app.on('ready', function() {
var mainWindow = new browserWindow({
width: 800,
height: 600
})
mainWindow.loadUrl('http://google.com');
})
答案 0 :(得分:0)
如果app是一个模块,那么你的package.json中就会丢失它。如果没有,您应该使用路径来要求它
var app = require('./app');
答案 1 :(得分:0)
您所遵循的指南已过时,从Electron v1.0.0开始,导入内置电子模块的方式已发生变化。这是正确的方法:
const {app, BrowserWindow} = require("electron")
您可能还会发现阅读上一个涵盖此主题的问题是有益的:What's the proper way to require in Node.js?