我正在尝试在我的NestJS项目上使用fastify-cookie,并且收到以下错误消息:
(节点:38325)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ decorateRequest”
UnhandledPromiseRejectionWarning:未处理的承诺拒绝。该错误是由于在没有catch块的情况下抛出异步函数而引起的,或者是由于拒绝了未经.catch()处理的诺言而引起的。要在未处理的承诺拒绝时终止节点进程,请使用CLI标志
--unhandled-rejections=strict
(请参见https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode)。 (拒绝ID:1) (节点:38904)[DEP0018] DeprecationWarning:已弃用未处理的承诺拒绝。将来,未处理的承诺拒绝将以非零退出代码终止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();
答案 0 :(得分:0)
您在这里使用Fastify,所以我想它一定是app.register
。
另外,您应该传递函数fastifyCookie
进行注册-app.register(fastifyCookie)
,您不应该自己调用此函数(删除()
)
p.s
要查看异常消息:
try {
await bootstrap();
} catch(ex){
console.log(ex);
}