在我的 app.js 文件中,我调用 swagger-ui 作为项目的一部分:
const swaggerUI = require("swagger-ui-express");
const YAML = require("yamljs");
const swaggerDocument = YAML.load("./swagger.yaml");
app.use(
"/swagger",
swaggerUI.serve,swaggerUI.setup(swaggerDocument)
);
当尝试使用 docker compose 运行项目时,我收到此错误:
app_back_end | [nodemon] 1.19.4
app_back_end | [nodemon] to restart at any time, enter `rs`
app_back_end | [nodemon] watching dir(s): *.*
app_back_end | [nodemon] watching extensions: js,mjs,json
app_back_end | [nodemon] starting `node --inspect=0.0.0.0 ./bin/www`
app_back_end | Debugger listening on ws://0.0.0.0:9229/0442f111-2e23-40db-a162-d67ed53acbc4
app_back_end | For help, see: https://nodejs.org/en/docs/inspector
app_back_end | internal/modules/cjs/loader.js:834
app_back_end | throw err;
app_back_end | ^
app_back_end |
app_back_end | Error: Cannot find module 'swagger-ui-express'
app_back_end | Require stack:
app_back_end | - /app/app.js
app_back_end | - /app/bin/www
app_back_end | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)
app_back_end | at Function.Module._resolveFilename (/app/node_modules/module-alias/index.js:49:29)
app_back_end | at Function.Module._load (internal/modules/cjs/loader.js:687:27)
app_back_end | at Module.require (internal/modules/cjs/loader.js:903:19)
app_back_end | at require (internal/modules/cjs/helpers.js:74:18)
app_back_end | at Object.<anonymous> (/app/app.js:81:19)
app_back_end | at Module._compile (internal/modules/cjs/loader.js:1015:30)
app_back_end | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
app_back_end | at Module.load (internal/modules/cjs/loader.js:879:32)
app_back_end | at Function.Module._load (internal/modules/cjs/loader.js:724:14)
app_back_end | at Module.require (internal/modules/cjs/loader.js:903:19)
app_back_end | at require (internal/modules/cjs/helpers.js:74:18)
app_back_end | at Object.<anonymous> (/app/bin/www:7:11)
app_back_end | at Module._compile (internal/modules/cjs/loader.js:1015:30)
app_back_end | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
app_back_end | at Module.load (internal/modules/cjs/loader.js:879:32)
app_back_end | at Function.Module._load (internal/modules/cjs/loader.js:724:14)
app_back_end | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
app_back_end | at internal/main/run_main_module.js:17:47 {
app_back_end | code: 'MODULE_NOT_FOUND',
app_back_end | requireStack: [ '/app/app.js', '/app/bin/www' ]
app_back_end | }
app_back_end | [nodemon] app crashed - waiting for file changes before starting...
虽然 swagger-express-ui 是使用 npm 下载的,但我收到这些错误,我能做些什么来修复它?
我通过运行解决了这个问题
npm install
似乎解决了问题
您必须在 docker 服务器上安装“swagger-ui-express”。您可以使用以下命令:
npm i swagger-ui-express