NestJS:类型“NestFastifyApplication”不满足约束“INestApplication”

问题描述 投票:0回答:2

我正在使用 NestJS 构建后端应用程序,并且尝试使用 fastify 而不是 express 作为底层框架。我按照文档(可在此处)使用 fastify,但是我遇到了以下类型问题:

Type 'NestFastifyApplication' does not satisfy the constraint 'INestApplication'.

Type 'NestFastifyApplication' is missing the following properties from type
'INestApplication': use, enableCors, enableVersioning, listenAsync, and 22 more

这里是代码:

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

async function bootstrap() {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter(),
  );
  await app.listen(3001);
}
bootstrap();
node.js typescript nestjs dependency-management fastify
2个回答
3
投票

问题很简单。安装

@nestjs/platform-fastify
期间出现问题。只需删除并安装软件包就足以解决

更新(感谢@JEFF)

基本上确保 package.json 中的 @nestjs/common、@nestjs/core 和 @nestjs/platform-{express/fastify} 版本匹配(reference)。


1
投票

PS:如果您有以下问题:

Type 'NestFastifyApplication<RawServerDefault>' does not satisfy the constraint 'INestApplication'.

也许@nestjs/platform 都存在兼容性版本问题- fastify 和 NestJS 核心包,所以运行

yarn upgrade-interactive --latest

将依赖项更新到最新的稳定版本。

参考:https://dev.to/ouelle/basic-crud-operations-with-nestjs-typescript-fastify-mongodb-1f1k

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.