nest
nest copied to clipboard
Typescript compilation error with fastify adapter
Did you read the migration guide?
- [X] I have read the whole migration guide
Is there an existing issue that is already proposing this?
- [X] I have searched the existing issues
Potential Commit/PR that introduced the regression
No response
NestJS version
10.3.0 -> 10.3.8
Describe the regression
After upgrading to the latest releases I'm getting typescript compilation errors.
This shows from and to:
[1 ~/git/koopa-api] yarn outdated
yarn outdated v1.22.22
info Color legend :
"<red>" : Major Update backward-incompatible updates
"<yellow>" : Minor Update backward-compatible features
"<green>" : Patch Update backward-compatible bug fixes
Package Current Wanted Latest Package Type URL
@nestjs/common 10.3.0 10.3.8 10.3.8 dependencies https://nestjs.com
@nestjs/core 10.3.0 10.3.8 10.3.8 dependencies https://nestjs.com
@nestjs/platform-fastify 10.0.5 10.3.8 10.3.8 dependencies https://nestjs.com
fastify 4.19.1 4.19.1 4.27.0 dependencies https://fastify.dev/
✨ Done in 4.79s.
[1 ~/git/koopa-api] yarn tsc:check
yarn run v1.22.22
$ tsc --noEmit
✨ Done in 1.56s.
[1 ~/git/koopa-api] yarn upgrade --latest @nestjs/common @nestjs/core @nestjs/platform-fastify fastify
:
✨ Done in 4.46s.
[1 ~/git/koopa-api] yarn tsc:check
yarn run v1.22.22
$ tsc --noEmit
src/app.ts:27:28 - error TS2345: Argument of type 'FastifyInstance<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault> & PromiseLike<...>' is not assignable to parameter of type 'FastifyHttp2Options<any, FastifyBaseLogger> | FastifyHttp2SecureOptions<any, FastifyBaseLogger> | FastifyHttpsOptions<...> | FastifyInstance<...> | FastifyServerOptions<...>'.
27 new FastifyAdapter(fastifyInstance),
~~~~~~~~~~~~~~~
:
The code in question is:
export async function createApp(): Promise<INestApplication> {
const fastifyInstance = fastify()
fastifyInstance.register(fastifyRequestContext, { defaultStoreValues: { localStorage: new LocalStorage() } })
fastifyInstance.addHook('onRequest', (req, reply, done) => {
requestContext.set('localStorage', new LocalStorage())
done()
})
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
/* @see https://docs.nestjs.com/techniques/performance#performance-fastify */
new FastifyAdapter(fastifyInstance),
{ bufferLogs: true },
)
return app
}
Minimum reproduction code
No response
Input code
Expected behavior
Either work as-is or some guidance on what I need to do to get it working.
Other
No response
In case it's relevant:
[1 ~/git/koopa-api] yarn nest info
yarn run v1.22.22
$ /Users/stbaldwin/git/koopa-api/node_modules/.bin/nest info
_ _ _ ___ _____ _____ _ _____
| \ | | | | |_ |/ ___|/ __ \| | |_ _|
| \| | ___ ___ | |_ | |\ `--. | / \/| | | |
| . ` | / _ \/ __|| __| | | `--. \| | | | | |
| |\ || __/\__ \| |_ /\__/ //\__/ /| \__/\| |_____| |_
\_| \_/ \___||___/ \__|\____/ \____/ \____/\_____/\___/
[System Information]
OS Version : macOS 23.5.0
NodeJS Version : v20.12.2
YARN Version : 1.22.22
[Nest CLI]
Nest CLI Version : 10.3.2
[Nest Platform Information]
platform-fastify version : 10.3.8
schematics version : 10.1.1
passport version : 10.0.3
testing version : 10.3.8
common version : 10.3.8
config version : 3.2.2
core version : 10.3.8
cli version : 10.3.2
✨ Done in 0.71s.
It seems that upgrading to the latest version of fastify (4.27.0) caused the issue. I checked the version defined in @nestjs/platform-fastify and saw it was 4.26.2. When I installed that version instead of the latest, I was able to use the latest versions of all the nestjs packages I'm using.
perhaps this will be fixed after releasing a new version of @nestjs/platform-fastify that has fastify v4.27 as a hard dep
https://github.com/nestjs/nest/blob/aa7538ffbe8608c41ece2a035b872e5032f57763/packages/platform-fastify/package.json#L24
https://github.com/nestjs/nest/releases/tag/v10.3.9