简体   繁体   English

运行“ npm start”时出错?

[英]Error when running “npm start”?

I have started with electron today and followed a guide to create a simple application browser window and I ran npm start in the command window and it displayed a lot of errors after I had entered it, I have posted the information below and my code. 我今天从电子开始,然后按照指南创建一个简单的应用程序浏览器窗口,并在命令窗口中运行了npm start,输入后它显示了很多错误,我在下面发布了信息和代码。

Console error: 控制台错误:

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

Here is my package.json: 这是我的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"
}

Here is my index.js: 这是我的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');
})

If app is a module, it's missing in your package.json. 如果app是模块,则package.json中缺少该模块。 If not, you should use a path to require it 如果没有,您应该使用一条路径来要求它

var app = require('./app');

The guide you followed is out of date, as of Electron v1.0.0 the way built-in Electron modules are imported has changed. 自从Electron v1.0.0起,导入的电子模块的导入方式已更改,因此您遵循的指南已过时。 This is the correct way: 这是正确的方法:

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

You may also find it beneficial to read the previous question that covered this topic: What's the proper way to require in Node.js? 您可能还会发现阅读涉及该主题的上一个问题很有帮助: Node.js中要求的正确方法是什么?

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

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