You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 05:27:42