0
votes

I'm trying to get fastify-cookie working on my NestJS project and I am receiving the following error:

(node:38325) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'decorateRequest' of undefined

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: 1) (node:38904) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

My code is as follows:

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();
1

1 Answers

0
votes

You are using Fastify here, so i guess it must be app.register. In addition you should pass the function fastifyCookie to register - app.register(fastifyCookie), you shouldn't call this function by yourself (remove ())

p.s

To see exception message:

try {
   await bootstrap();
} catch(ex){
   console.log(ex);
}