javascript - 如何在 Nestjs 中安装 Swagger?

标签 javascript nestjs nestjs-swagger

我无法在我的 nestjs 应用程序中安装 swagger。当我尝试时,出现错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: test.api@0.0.1
npm ERR! Found: @nestjs/common@8.4.7
npm ERR! node_modules/@nestjs/common
npm ERR!   @nestjs/common@"^8.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @nestjs/common@"^9.0.0" from @nestjs/swagger@6.0.1
npm ERR! node_modules/@nestjs/swagger
npm ERR!   dev @nestjs/swagger@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\Jakub\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Jakub\AppData\Local\npm- cache\_logs\2022-07-10T11_03_48_876Z-debug-0.log

如何解决?

最佳答案

NestJS 9 最近发布(2 天前)。

https://trilon.io/blog/nestjs-9-is-now-available .

已对 @nestjs/swagger 包进行更改。您正在安装最新版本,该版本对 NestJS 9 具有对等依赖性,而您的项目仍在版本 8.4.7 上。

错误是说它无法解析请求的对等依赖 @nestjs/common@^9.0.0。它确实找到了 @nestjs/common@8.4.7,但这不兼容。

升级 NestJS 或安装与您的应用程序使用的 NestJS 版本兼容的旧版本 @nestjs/swagger 包。版本 5.2.1 应该适合您。

yarn add @nestjs/swagger@5.2.1
OR
npm i @nestjs/swagger@5.2.1

关于javascript - 如何在 Nestjs 中安装 Swagger?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72928034/

相关文章:

javascript - Node.js:创建 Web Hook

javascript - JS如何正确替换元素?

javascript - 当条件成立时如何禁用 onbeforeunload ?

nestjs - 如何在 NestJS 中跨模块全局注入(inject)值(value)?

node.js - 在 NestJS 中创建代理

typescript - 如果不单独使用,nestjs/swagger 是否支持查询参数的文档?

javascript - React - 将对象转换为具有属性的对象数组

node.js - 如何在 DTO nestJs 上设置默认值?

swagger - 用于 postman 的 NestJs Swagger

NestJs/招摇 : Define ref schemas without DTO classes