Alexandre29
Alexandre29

Reputation: 97

NestJs registering Fastify/Cookie plugin

Hi i am trying to register the @fastify/cookie plugin to my nestjs backend but i have an error and i don't know why because in previous code i was doing the same thinks and was working , i don't know if versions changed or if there is a new way of registering plugins with nestJs -> Fastify

here is my code

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import fastifyCookie from '@fastify/cookie';

async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
  AppModule,
  new FastifyAdapter(),
);

await app.register(fastifyCookie, { secret: '' });
await app.listen(3005);
}

bootstrap();

and i am getting

Argument of type 'FastifyCookie' is not assignable to parameter of type 'FastifyPluginCallback<FastifyCookieOptions, RawServerDefault, FastifyTypeProviderDefault, FastifyBaseLogger> | FastifyPluginAsync<...> | Promise<...> | Promise<...>'

here are the versions i am using

Upvotes: 5

Views: 1950

Answers (1)

Attila Herczog
Attila Herczog

Reputation: 1

You should match the version of the installed fastify package to the version used in @nestjs/platform-fastify.

  1. Probably it's better to have the platform-fastify version fixed:
    npm i @nestjs/platform-fastify --save-exact
  2. Open node_modules/@nestjs/platform-fastify/package.json
  3. Search for the version in the dependencies: "fastify": "4.28.0",
  4. Install the same version in your project: npm i [email protected] --save-exact

By doing these steps I was able to make the @fastify/cookie plugin registered.

My versions after the fix:

"@nestjs/core": "^10.0.0"
"@nestjs/platform-fastify": "10.3.10"
"fastify": "4.28.0"
"@fastify/cookie": "^9.3.1"

Upvotes: 0

Related Questions