首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NestJS Graphql Fastify FastifyError: fastify-plugin: fastify -接受-预期的'3.x‘fastify版本,'4.6.0’已安装

NestJS Graphql Fastify FastifyError: fastify-plugin: fastify -接受-预期的'3.x‘fastify版本,'4.6.0’已安装
EN

Stack Overflow用户
提问于 2022-09-21 21:21:55
回答 1查看 41关注 0票数 0

我遵循关于如何使用nest设置fastify /阿波罗服务器的NestJS文档,但是在向main.ts中添加fastify之后,我得到了以下错误:

代码语言:javascript
复制
FastifyError: fastify-plugin: fastify-accepts - expected '3.x' fastify version, '4.6.0' is installed

我尝试过安装fastify 3.x,改变了其他模块的版本,但是根据yarn.lock,一些模块需要3.x,其他模块需要4.x。

这些是我要跟踪的文档:

  1. https://docs.nestjs.com/techniques/performance
  2. https://docs.nestjs.com/graphql/quick-start

这是我的main.ts

代码语言:javascript
复制
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import {
  FastifyAdapter,
  NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { ValidationPipe } from '@nestjs/common';

async function bootstrap() {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter({ logger: true }),
  );

  app.useGlobalPipes(new ValidationPipe());
  await app.listen(3000);
  console.log(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();

这是我的package.json

代码语言:javascript
复制
{
  "name": "app",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "prebuild": "rimraf dist",
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@nestjs/apollo": "^10.1.0",
    "@nestjs/common": "^9.0.0",
    "@nestjs/core": "^9.0.0",
    "@nestjs/graphql": "^10.1.2",
    "@nestjs/platform-express": "^9.0.0",
    "@nestjs/platform-fastify": "^9.1.1",
    "apollo-server-fastify": "^3.10.2",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.13.2",
    "firebase-admin": "^11.0.1",
    "graphql": "^16.6.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0",
    "ts-morph": "^16.0.0"
  },
  "devDependencies": {
    "@nestjs/cli": "^9.0.0",
    "@nestjs/schematics": "^9.0.0",
    "@nestjs/testing": "^9.0.0",
    "@types/express": "^4.17.13",
    "@types/jest": "28.1.8",
    "@types/node": "^16.0.0",
    "@types/supertest": "^2.0.11",
    "@typescript-eslint/eslint-plugin": "^5.0.0",
    "@typescript-eslint/parser": "^5.0.0",
    "eslint": "^8.0.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-prettier": "^4.0.0",
    "jest": "28.1.3",
    "prettier": "^2.3.2",
    "source-map-support": "^0.5.20",
    "supertest": "^6.1.3",
    "ts-jest": "28.0.8",
    "ts-loader": "^9.2.3",
    "ts-node": "^10.0.0",
    "tsconfig-paths": "4.1.0",
    "typescript": "^4.7.4"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".*\\.spec\\.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "collectCoverageFrom": [
      "**/*.(t|j)s"
    ],
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}
EN

回答 1

Stack Overflow用户

发布于 2022-09-21 21:27:52

@nestjs/common@^9@nestjs/platform-fastify@^9要求您使用fastify@^4。然而,除非阿波罗服务器apllo-server-fastify fastify@^4 v4问世,否则它不会出现.在那之前。你可以跟随文档,使用mercurius代替

另一种选择是降级为@nestjs/common@^8@nestjs/platform-fastify@^8,以及支持fastify@^3@nestjs/graphql@^9

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73807059

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档