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

升级NestJS v11与Apollo Server v5为何需安装as-integrations/express5?

问题:NestJS v11 + Apollo Server v5 升级后必须安装未显式使用的 @as-integrations/express5?

我们的项目原本基于 NestJS v10、Apollo Server v4 和 Express v4 开发。升级到 NestJS v11 与 Apollo Server v5 后,首先遇到了必须安装 Express v5 的 peer dependency 问题;安装 Express v5 后,服务器又因为缺失 @as-integrations/express5 无法启动,只有安装该库后服务器才能正常运行。

我们并没有在项目中显式使用 @as-integrations/express5,也没有任何相关代码引用,但运行 NestJS 和 Apollo 却要求把它作为直接依赖。npm 没有发出类似 peer 依赖的警告,这个问题甚至通过了 CI 流程进入了预生产环境,而且我们也没有使用 Express 中间件。

想请教:

  • 是否存在无需直接安装 @as-integrations/express5 的原因或规避方案?
  • 是不是我忽略了某些必须引入这个未显式使用依赖的要点?

项目相关依赖示例

"dependencies": {
    "@apollo/server": "5.2.0",
    "@apollo/subgraph": "2.12.2",
    "@as-integrations/express5": "^1.1.2",
    "@graphql-tools/load-files": "7.0.1",
    "@graphql-tools/merge": "9.1.7",
    "@nestjs/apollo": "13.2.3",
    "@nestjs/axios": "4.0.1",
    "@nestjs/cache-manager": "3.1.0",
    "@nestjs/common": "11.1.11",
    "@nestjs/config": "4.0.2",
    "@nestjs/core": "11.1.11",
    "@nestjs/graphql": "13.2.3",
    "@nestjs/platform-express": "11.1.11",
    "@nestjs/swagger": "11.2.4",
    "@nestjs/terminus": "11.0.0",
    "express": "5.2.1",
    "graphql": "16.12.0",
    "graphql-tag": "2.12.6"   
  }

解答

为什么必须安装 @as-integrations/express5?

这是因为 @nestjs/apollo v13+(适配 NestJS v11)在集成 Apollo Server v5 时,内部会自动依赖 @as-integrations/express5 完成与 Express v5 的适配。Apollo Server v5 不再内置 Express 集成,而是把不同框架的集成拆分到单独的 @as-integrations/* 包中。但 @nestjs/apollo 没有在自身的依赖声明中正确标记这个包为 peer dependency 或自动安装依赖,导致 npm 没提前发出警告,需要你手动补充。

无需显式安装的规避方案

  1. 降级回 Express v4:如果项目没有必须使用 Express v5 的需求,把 express 版本降回 v4.x,同时移除 @as-integrations/express5。此时 @nestjs/apollo 会自动使用适配 Express v4 的 @as-integrations/express,这个包会作为间接依赖被自动安装,不需要手动添加。
  2. 等待 @nestjs/apollo 依赖修复:后续 @nestjs/apollo 可能会修复依赖声明问题,把 @as-integrations/express5 标记为 peer dependency 或加入自身依赖,届时 npm 会自动处理安装。可以关注该包的更新日志,升级到修复后的版本。

你可能忽略的要点

  • Apollo Server v5 的架构变化:它将框架集成逻辑完全抽离到独立包中,不再像 v4 那样内置 Express 支持,因此对接不同版本的 Express 必须搭配对应的集成包。
  • @nestjs/platform-express v11 仅适配了 Express v5 的基础运行,但没有处理 Apollo Server 所需的集成依赖,导致这个缺口需要手动填补。

内容的提问来源于stack exchange,提问作者Greg

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.11 17:13:09