1

我正在使用NestJS版本7.1.0serverless创建 api 文档使用nestjs swagger. 在本地它像冠军一样工作,但在部署后出现错误。

swagger-ui-express package is missing

我在这里看到了一些问题,但仍未解决此问题。 https://github.com/nestjs/swagger/issues/277

这是我的package.json

"dependencies": {
    "@nestjs/common": "^7.1.0",
    "@nestjs/core": "^7.1.0",
    "@nestjs/passport": "^7.0.0",
    "@nestjs/platform-express": "^7.0.7",
    "@nestjs/swagger": "^4.5.8",
    "aws-serverless-express-binary": "^1.0.1",
    "class-transformer": "^0.2.3",
    "class-validator": "^0.11.1",
    "dayjs": "^1.8.24",
    "dotenv": "^8.2.0",
    "dynamodb-data-types": "^3.0.1",
    "express": "^4.17.1",
    "faker": "^4.1.0",
    "jest": "^24.9.0",
    "jwks-rsa": "^1.6.0",
    "latinize": "^0.4.1",
    "lodash": "^4.17.15",
    "mime-types": "^2.1.26",
    "passport": "^0.4.1",
    "passport-jwt": "^4.0.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.0",
    "rxjs": "^6.5.3",
    "serverless-dynamodb-local": "^0.2.39",
    "swagger-ui-express": "^4.1.4",
    "tslint-loader": "^3.5.4",
    "uuid": "^3.3.3",
    "winston": "^3.2.1"
  },

这是配置:

const options = new DocumentBuilder()
  .setTitle("My APIs")
  .setDescription("APIs description")
  .setVersion("1.0")
  .addTag("cats")
  .build();

const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup("api", app, document);

任何帮助!

4

4 回答 4

3

我的解决方案是安装快递:

npm i express
于 2022-02-02T13:09:09.503 回答
0

我想出了解决方案,希望这对某人有所帮助。我添加了一个假端点以确保在运行swagger-ui-express后不会被删除webpack

if (event.path === "/api") {
    event.path = "/api/";
} else if (event.path.includes("/swagger-ui")) {
    event.path = event.path.replace("/swagger-ui", "/api/swagger-ui");
}

// Fake to keep swagger-ui-express work after deploy
if (event.path === "/fake-swagger-ui-express") {
    swaggerUi.setup(null);
}
于 2020-07-22T06:15:44.053 回答
0

我不得不跑:

纱线安装

要解决这个问题。

于 2022-01-19T14:26:00.890 回答
-1

你碰巧在使用纱线工作区吗?我刚才遇到了同样的问题,本地一切正常,但在我们的集群上坏了。

如果是,请尝试将其添加到使用 swagger 模块的 API 的 package.json 中: "workspaces": { "nohoist": ["swagger-ui-express"] }

于 2020-07-20T15:17:56.300 回答