I'm new to NestJS Fastify. I use NestJS with express as a default before. I'd like to try using fastify this time, but got a type error when registering FastifyHelmet to app Instance.
*notes: I also new to ask question in this forum, so feel free to correct me.
I'm following the official docs like this:
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
// inside bootstrap() function
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
{
...secureOptions,
logger: new CustomLogger(),
cors: true, // change this to Client IP when Production
},
);
await app.register(helmet);
I don't know if i missed something, but it shows a type error like this:
Argument of type 'typeof fastifyHelmet' is not assignable to parameter of type 'FastifyPluginCallback | FastifyPluginAsync | Promise<...> | Promise<...>'. Type 'typeof fastifyHelmet' is not assignable to type 'FastifyPluginCallback'. Types of parameters 'instance' and 'instance' are incompatible.
This is my current dependencies:
"dependencies":{
"@fastify/helmet": "^11.1.1",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.1.1",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-fastify": "^10.3.3",
// other packages
}
After I research to github issues. I found out that the version of fastify is not match to @nestjs/platform-fastify.
For now, as a temporary solution. I change the version of fastify@4.26.1 to fastify@4.26.0