Swagger 主题版本已弃用

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

我正在 ubuntu ec2 机器上部署我的 Node js 后端,但是部署时出现以下错误

  at node:internal/main/run_main_module:22:47
2| Error: Explicit version indication is deprecated
2|    at SwaggerTheme.getBuffer (/home/ubuntu/var/www/obenan-api-v20240731171044/node_modules/swagger-themes/build/swagger-theme.js:36:19)
2|     at Object.<anonymous> (/home/ubuntu/var/www/obenan-api-v20240731171044/index.js:200:19)
2|o     at Module._compile (node:internal/modules/cjs/loader:1198:14)
2|     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
2|     at Module.load (node:internal/modules/cjs/loader:1076:32)
2|at Function.Module._load (node:internal/modules/cjs/loader:911:12)
2|    at Object.<anonymous> (/home/ubuntu/.nvm/versions/node/v16.20.2/lib/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
2|    at Module._compile (node:internal/modules/cjs/loader:1198:14)
2|    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
2|     at Module.load (node:internal/modules/cjs/loader:1076:32)
2|    at Function.Module._load (node:internal/modules/cjs/loader:911:12)
2|   at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
2|     at node:internal/main/run_main_module:22:47

我使用的代码是

const swaggerUi = require('swagger-ui-express');
const swagger = require('./swagger.json');
const { SwaggerTheme } = require('swagger-themes');

swagger.host = process.env.BACKEND_BASE_URL;
swagger.schemes = process.env.BACKEND_BASE_URL == 'localhost:4000' ? ['http'] : ['https'];

const theme = new SwaggerTheme('v3');

const options = {
    explorer: true,
    customCss: theme.getBuffer('dark'),
};

app.use('/swagger', swaggerUi.serve, swaggerUi.setup(swagger, options));

const port = config.port || 4000;
const server = app.listen(port, () => {
    log(color.yellow(' ******************************************** '));
    log(color.yellow(' *******                    ******* '));
    log(color.yellow(` ******* Server is running on ${port}    ******* `));
    log(color.yellow(' *******                              ******* '));
    log(color.yellow(' ******************************************** '));
});

我期待看到服务器在 swagger ui 中的端口上运行。我被困在这个了

node.js ubuntu swagger-ui aws-codepipeline
1个回答
0
投票

错误来自此代码

这表明你应该这样做

const theme = new SwaggerTheme();

而不是

const theme = new SwaggerTheme('v3');

如果您只在生产中遇到此错误,而不是在开发中遇到此错误,则表明您在生产中至少有此软件包的不同版本。发展。考虑确保遵守您的

package-lock.json
(例如在生产和 CI 中运行
npm ci
)。

© www.soinside.com 2019 - 2024. All rights reserved.