【发布时间】:2020-05-18 03:58:12
【问题描述】:
我正在尝试在我的 NestJS 项目中使用 fastify-cookie,但收到以下错误:
(node:38325) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'decorateRequest' of undefined
UnhandledPromiseRejectionWarning:未处理的承诺拒绝。此错误源于在没有 catch 块的情况下抛出异步函数内部,或拒绝未使用 .catch() 处理的承诺。要在未处理的 Promise 拒绝时终止节点进程,请使用 CLI 标志
--unhandled-rejections=strict(请参阅 https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode)。 (拒绝编号:1) (节点:38904)[DEP0018] DeprecationWarning:不推荐使用未处理的承诺拒绝。将来,未处理的 Promise 拒绝将使用非零退出代码终止 Node.js 进程。
我的代码如下:
import { NestFactory } from "@nestjs/core";
import { FastifyAdapter, NestFastifyApplication } from "@nestjs/platform-fastify";
import fastifyCookie = require("fastify-cookie");
import { AppModule } from "./app.module";
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter()
);
app.enableCors({ origin: "http://localhost:3000", credentials: true });
app.use(fastifyCookie());
await app.listen(8000);
}
bootstrap();
【问题讨论】:
标签: javascript node.js promise nestjs fastify