在NestJS+Fastify项目中注册@fastify/multipart的类型不兼容问题
NestJS + Fastify 注册@fastify/multipart插件类型不兼容问题
我正在开发基于Fastify的NestJS应用,注册@fastify/multipart插件时遇到类型不兼容错误,代码配置如下:
import multiPart from '@fastify/multipart'; import { NestFastifyApplication } from '@nestjs/platform-fastify'; import { RawServerDefault } from 'fastify'; export const setupPlugins = async (app: NestFastifyApplication<RawServerDefault>) => { await app.register(multiPart, { limits: { fileSize: 1000000, } }); }
已尝试更新所有相关依赖到最新版本:
npm install fastify@latest npm install @fastify/multipart@latest npm install @nestjs/platform-fastify@latest
但仍收到编译错误:
Compilation error in /usr/app/src/app/setup/plugins.ts error TS2345: Argument of type 'FastifyMultipartPlugin' is not assignable to parameter of type 'FastifyPluginCallback<FastifyMultipartOptions> | FastifyPluginAsync<FastifyMultipartOptions> | Promise<...> | Promise<...>'. Type 'FastifyMultipartPlugin' is not assignable to type 'FastifyPluginCallback<FastifyMultipartOptions>'. Types of parameters 'instance' and 'instance' are incompatible. Type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>' is missing the following properties from type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>': propfind, proppatch, mkcalendar, mkcol, and 8 more.
已尝试以下解决方案但无效:
- 在tsconfig.json中启用
esModuleInterop和allowSyntheticDefaultImports - 使用
require替代import导入插件 - 对齐所有相关依赖版本
当前依赖版本:
- fastify@4.28.1
- @nestjs/platform-fastify@10.4.8
- @fastify/multipart@8.3.0
求解决该类型不兼容问题。
内容的提问来源于stack exchange,提问作者Rori
相关产品推荐
相关产品推荐

