简体   繁体   English

如何修复节点服务器错误 npm ERR? 代码 ELIFECYCLE npm 错误! 错误1?

[英]How do I fix a node server error, npm ERR! code ELIFECYCLE npm ERR! errno 1?

npm ERR. npm 错误。 code ELIFECYCLE npm ERR.代码 ELIFECYCLE npm 错误。 errno 1 npm ERR: node-express@1.0.0 start: node server npm ERR. errno 1 npm ERR:node-express@1.0.0 开始: node server npm ERR。 Exit status 1 npm ERR.退出状态 1 npm ERR。 npm ERR. npm 错误。 Failed at the node-express@1.0.0 start script.在 node-express@1.0.0 启动脚本中失败。 npm ERR! npm 错误! This is probably not a problem with npm.这可能不是 npm 的问题。 There is likely additional logging output above.上面可能还有额外的日志记录 output。

npm ERR: A complete log of this run can be found in. npm ERR. npm ERR:此运行的完整日志可在 npm ERR 中找到。 /Users/teevee/.npm/_logs/2020-05-30T18_42_30_526Z-debug.log /Users/teevee/.npm/_logs/2020-05-30T18_42_30_526Z-debug.log

I haven't had any issues until I had to add routes for partners and promotions in my project.直到我不得不在我的项目中为合作伙伴和促销添加路线之前,我没有遇到任何问题。 I don't know how to debug this type of error in order to make the needed changes.我不知道如何调试此类错误以进行所需的更改。 What can possibly be the issue?可能是什么问题? I'm still learning.我还在学习。 Here is a link: https://github.com/TanishaV842/node-express/tree/master/routes这是一个链接: https://github.com/TanishaV842/node-express/tree/master/routes

One of the issues you have is that it looks like you're including code for your routers in multiple places:您遇到的问题之一是您似乎在多个地方包含了路由器的代码:

// server.js

app.use("/campsites", campsiteRouter);
app.use("/partners", partnerRouter);
app.use("/promotions", promotionRouter);

campsiteRouter.route("/campsites").all(...);
partnerRouter.route("/partners").all(...);
promotionsRouter.route("/promotions").all(...);

There's no need to do that, just do app.use("/campsites", campsiteRouter);没有必要这样做,只需执行app.use("/campsites", campsiteRouter); and get rid of the router code inside server.js .并摆脱server.js中的路由器代码。


Second, the code inside of your routers is incorrect in two ways:其次, routers内部的代码在两个方面不正确:

// these are two different routes, so create a separate
// route for `/campsites/:campsiteId`,
// additionally, you don't want to do `/campsites/:campsiteId` 
// because you specified the `/campsite` route/portion inside of 
// your `server.js` file when you did 
// `app.use("/campsites", campsiteRouter)`, so only use `/:campsiteId`

// WRONG
campsiteRouter
  .route("/campsites")
  .all(...)
  .get("/campsites/:campsiteId", ...)

// CORRECT
campsiteRouter
  .route("/:campsiteId")
  .all(...)
  .get((req, res) => {
    console.log(req.params.campsiteId);
  })
  .post(...);

Here's your fixed code:这是您的固定代码:

Hope this helps.希望这可以帮助。

It looks like you're mixing up regular router.get() with router.route().get() method parameters.看起来您将常规router.get()router.route().get()方法参数混合在一起。

Because you're using the router.route() method, your:因为您使用的是router.route()方法,所以您的:

.get() .post() .delete() .get() .post() .delete()

call can't pass in a string and a callback. call 不能传入字符串和回调。 They only except a callback function.他们只有一个回调 function。

To fix,修理,

change all of the router.route(...).get('<path>', (req, res) => {})更改所有router.route(...).get('<path>', (req, res) => {})

to something like:类似于:

router.route(...).get((req, res) => {})

No path parameter.没有路径参数。

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

相关问题 如何修复错误:MD5 校验和迁移失败 [1] npm ERR! 代码 ELIFECYCLE npm ERR! 错误号 1 - How to fix Error: MD5 checksum failed for migration [1] npm ERR! code ELIFECYCLE npm ERR! errno 1 npm 错误! 代码 ELIFECYCLE npm ERR! 错误 2 - npm ERR! code ELIFECYCLE npm ERR! errno 2 npm 错误! 代码 ELIFECYCLE npm 错误! 错误号 1 - npm ERR! code ELIFECYCLE npm ERR! errno 1 如何解决 npm err 代码 elifecycle 错误? - How to solve npm err code elifecycle error? 调试npm ERR! 代码 ELIFECYCLE npm 错误! 错误号 1 - debugging npm ERR! code ELIFECYCLE npm ERR! errno 1 反应 npm 错误“npm ERR! 代码 ELIFECYCLE” 当我执行 npm start 时 - React npm error “npm ERR! code ELIFECYCLE” when I do npm start 如何解决“npm ERR? 代码ELIFECYCLE”在反应? - How to solve “npm ERR! code ELIFECYCLE” in react? 在运行 npm install 时获取“npm ERR!code ELIFECYCLE npm ERR!errno 126” - Getting "npm ERR! code ELIFECYCLE npm ERR! errno 126" while running npm install 如何解决 Windows 中的“npm ERR!code ELIFECYCLE”错误 - How to resolve "npm ERR! code ELIFECYCLE" error in windows 在节点 js“应该设置秘密”和反应“npm ERR!代码 ELIFECYCLE”中出现错误 - Getting error in node js "secret should be set" and in react "npm ERR! code ELIFECYCLE"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM