Nodejs 中出现类型错误的 UnhandledPromiseRejectionWarning

当我在nodejs中运行node server.js时,错误消息显示“无法读取未定义的属性‘长度’”。我已经安装了所有相关的库(例如请求)并查看了不同的相关帖子。然而,问题仍然存在。我认为这与快递或索引文件有关。有什么建议吗?非常感谢!


(node:14320) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined

at 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)


慕容708150
浏览 336回答 1
1回答

慕盖茨4494581

传递undefinedornull值app.use将导致显示的错误。所以我猜测您使用的环境变量有问题,例如:app.use(process.env.ROUTING_PREFIX,&nbsp;routes.default);尝试执行 aconsole.log(process.env.ROUTING_PREFIX)并检查该值是否已设置或者是否为undefined.
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript