简体   繁体   English

NodeJS - TypeError:Busboy 不是构造函数

[英]NodeJS - TypeError: Busboy is not a constructor

So, something happened a couple of days ago and a project of mine started showing the following error:所以,几天前发生了一些事情,我的一个项目开始显示以下错误:

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)

What I think is strange is that this Busboy isn't being used on my code, only in dependencies from node_modules.我认为奇怪的是,这个 Busboy 没有在我的代码中使用,仅在来自 node_modules 的依赖项中使用。 Does anyone know if there is any compatibility error with the version of Busboy or any of those listed in the error that could cause such thing?有谁知道 Busboy 的版本或错误中列出的任何可能导致此类问题的版本是否存在兼容性错误?

Look, node_modules doesn't only contain the packages, which you installed, it also contains dependencies of your installed packages.看,node_modules 不仅包含您安装的包,它还包含已安装包的依赖项。 So a good practice is to use lock files as package-lock.json, which will lock every package's version and every time you run npm install it installs the exact locked versions (to be more precise - with npm ci script).因此,一个好的做法是将锁定文件用作 package-lock.json,这将锁定每个包的版本,并且每次运行npm install它都会安装精确的锁定版本(更准确地说 - 使用npm ci So in this case as I see one of your packages has been updated or maybe that "busboy" package has been updated and after you ran install script it brought to you the updated package (or packages) which involves this error.因此,在这种情况下,我看到您的一个软件包已更新,或者“busboy”package 已更新,并且在您运行安装脚本后,它为您带来了涉及此错误的更新的 package(或软件包)。

Just adding another answer for someone who might be confused.只是为可能感到困惑的人添加另一个答案。 Busboy exports a function and not a class. Busboy 导出的是 function 而不是 class。 So, one need not use new keyword for creating an instance of Busboy.因此,不需要使用 new 关键字来创建 Busboy 的实例。

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

This answer is only to provide clarity to someone who is confused based on multiple examples and tutorials.这个答案只是为了让那些因多个示例和教程而感到困惑的人更加清楚。 Please suggest improvements if any.如果有任何改进,请提出改进建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM