docker node.js项目找不到swagger-ui-express模块

r6vfmomb  于 2023-08-03  发布在  Docker
关注(0)|答案(1)|浏览(111)

在我的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下载的,但我得到了这些错误,我能做些什么来修复它?

kokeuurv

kokeuurv1#

我通过逃跑解决了这个问题

npm install

字符串
似乎解决了这个问题

相关问题