为了账号安全,请及时绑定邮箱和手机立即绑定

Nodejs 中出现类型错误的 UnhandledPromiseRejectionWarning

Nodejs 中出现类型错误的 UnhandledPromiseRejectionWarning

慕容708150 2023-12-14 14:08:22
当我在nodejs中运行node server.js时,错误消息显示“无法读取未定义的属性‘长度’”。我已经安装了所有相关的库(例如请求)并查看了不同的相关帖子。然而,问题仍然存在。我认为这与快递或索引文件有关。有什么建议吗?非常感谢!(node:14320) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefinedat pathtoRegexp (/home/floyd/Desktop/icigai/marketplace_backend/node_modules/path-to-regexp/index.js:63:49)at new Layer (/home/floyd/Desktop/icigai/marketplace_backend/node_modules/express/lib/router/layer.js:45:17)at Function.use (/home/floyd/Desktop/icigai/marketplace_backend/node_modules/express/lib/router/index.js:464:17)at Function.<anonymous> (/home/floyd/Desktop/icigai/marketplace_backend/node_modules/express/lib/application.js:220:21)at Array.forEach (<anonymous>)at Function.use (/home/floyd/Desktop/icigai/marketplace_backend/node_modules/express/lib/application.js:217:7)at _default (/home/floyd/Desktop/icigai/marketplace_backend/src/loaders/express.js:28:9)at _callee$ (/home/floyd/Desktop/icigai/marketplace_backend/src/loaders/index.js:8:11)at tryCatch (/home/floyd/Desktop/icigai/marketplace_backend/node_modules/regenerator-runtime/runtime.js:63:40)at Generator.invoke [as _invoke] (/home/floyd/Desktop/icigai/marketplace_backend/node_modules/regenerator-runtime/runtime.js:293:22)(node:14320) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
查看完整描述

1 回答

?
慕盖茨4494581

TA贡献1850条经验 获得超11个赞

传递undefinedornullapp.use将导致显示的错误。所以我猜测您使用的环境变量有问题,例如:

app.use(process.env.ROUTING_PREFIX, routes.default);

尝试执行 aconsole.log(process.env.ROUTING_PREFIX)并检查该值是否已设置或者是否为undefined.


查看完整回答
反对 回复 2023-12-14
  • 1 回答
  • 0 关注
  • 63 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信