node.js - mime.lookup 不是在 docker 内运行的expressjs中的函数

标签 node.js express docker

我有一个运行 Node 进程的 docker 镜像。它正在监听特定端口。当我尝试使用curl或通过浏览器请求访问端口时,出现以下错误 -

类型错误:mime.lookup 不是函数 在 ServerResponse.contentType (/E:/Saurabh/node_modules/express/lib/response.js:592:12) 在 ServerResponse.send (/E:/Saurabh/node_modules/express/lib/response.js:145:14) 在 app.get (/E:/Saurabh/apis/index.js:26:6) 在 Layer.handle [作为handle_request] (/E:/Saurabh/node_modules/express/lib/router/layer.js:95:5) 接下来(/E:/Saurabh/node_modules/express/lib/router/route.js:137:13) 在 Route.dispatch (/E:/Saurabh/node_modules/express/lib/router/route.js:112:3) 在 Layer.handle [作为handle_request] (/E:/Saurabh/node_modules/express/lib/router/layer.js:95:5) 在/E:/Saurabh/node_modules/express/lib/router/index.js:281:22 在 Function.process_params (/E:/Saurabh/node_modules/express/lib/router/index.js:335:12) 接下来 (/E:/Saurabh/node_modules/express/lib/router/index.js:275:10)

如果我在没有 docker 的情况下运行相同的代码,那么它会按预期工作。 可能是什么问题?

最佳答案

至于npm documentation on mime :

Version 2 is a breaking change from 1.x as the semver implies. Specifically:

  • lookup() renamed to getType()

If you prefer the legacy version of this module please npm install mime@^1.

只需将调用方法的方式更改为 mime.getType(path) 或卸载 mime npm uninstall mime 并将其重新安装为 npm install mime@^ 1.

关于node.js - mime.lookup 不是在 docker 内运行的expressjs中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47825700/

相关文章:

node.js - 从我的 Node.js 服务器下载文件时出错

javascript - 使用javascript将数组重组为数组数组

javascript - 当伪 javascript 类已经初始化时,我在尝试修改 "this"对象时遇到了很多麻烦

javascript - Node.js, 'X' 未定义

docker - 在 Container 中挂载目录并与 Host 共享

php - docker 图像的 Alpine 语言环境 (php gettext)

javascript - Sequelize 中虚拟字段的 Getter 和 Setter

javascript - 无法修改nodejs模块值

node.js - 带有套接字 IO 问题的 Express JS Controller

docker - docker 入口点没有这样的文件或目录