javascript - NodeJS-类型错误 : Busboy is not a constructor

标签 javascript node.js busboy

所以,几天前发生了一些事情,我的一个项目开始显示以下错误:

TypeError: Busboy is not a constructor
at /app/node_modules/connect-busboy/index.js:21:18
at /app/node_modules/express-fileupload/lib/index.js:9:31
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/app/node_modules/express/lib/router/index.js:323:13)
at /app/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/app/node_modules/express/lib/router/index.js:341:12)
at next (/app/node_modules/express/lib/router/index.js:275:10)
at urlencodedParser (/app/node_modules/body-parser/lib/types/urlencoded.js:100:7)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/app/node_modules/express/lib/router/index.js:323:13)
at /app/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/app/node_modules/express/lib/router/index.js:341:12)
at next (/app/node_modules/express/lib/router/index.js:275:10)
at jsonParser (/app/node_modules/body-parser/lib/types/json.js:119:7)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/app/node_modules/express/lib/router/index.js:323:13)
at /app/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/app/node_modules/express/lib/router/index.js:341:12)
at next (/app/node_modules/express/lib/router/index.js:275:10)
at logger (/app/node_modules/morgan/index.js:144:5)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/app/node_modules/express/lib/router/index.js:323:13)

我认为奇怪的是,这个 Busboy 没有在我的代码中使用,仅在 node_modules 的依赖项中使用。有谁知道 Busboy 的版本是否存在任何兼容性错误或错误中列出的任何可能导致此类问题的错误?

最佳答案

只是为可能感到困惑的人添加另一个答案。 Busboy 导出一个函数而不是一个类。因此,不需要使用 new 关键字来创建 Busboy 的实例。

const Busboy = require('busboy');
const busboy = Busboy({ headers: req.headers });

这个答案只是为了让那些对多个示例和教程感到困惑的人更加清晰。如果有任何改进,请提出建议。

关于javascript - NodeJS-类型错误 : Busboy is not a constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70769641/

相关文章:

javascript - three.js 的机械臂 Action

javascript - 如何使用发布请求从浏览器上传图像 Instagram

node.js - Nodejs get请求读取body数据

ajax - 文件上传失败

node.js - 如何在以多部分形式处理文件流之前等待字段

javascript - 如何使用 Busboy 检测上传流意外停止

javascript - 如何仅对 1 个 Angular 使用边界半径(react-native)?

javascript - for 循环和解构

node.js - WebStorm 在导入时显示保留字

node.js - 如何使 App Engine 标准上的 Node JS 日志像 Python 一样好