NodeJS - TypeError: Busboy is not a constructor
Asked Answered
F

3

7

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. 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?

Ferreby answered 19/1, 2022 at 11:18 Comment(0)
A
1

Look, node_modules doesn't only contain the packages, which you installed, it also contains dependencies of your installed packages. 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). 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.

Ameba answered 19/1, 2022 at 16:37 Comment(2)
I was trying to figure out what package was giving me this problem and I found out that express-fileupload was the one. I deleted the version I had and updated it and it worked. Thx for the heads up either way, was a good oneFerreby
Glad that it helped, I had that kind of strange things during my experience as well)Ameba
H
12

Just adding another answer for someone who might be confused. Busboy exports a function and not a class. So, one need not use new keyword for creating an instance of 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.

Heehaw answered 30/8, 2022 at 4:10 Comment(1)
I have changed my import statement like you suggested but nothing changed. I am still getting the "Error [TypeError]: Busboy is not a constructor" error. How am I supposed to know which package is conflicting with this.Instability
A
1

Look, node_modules doesn't only contain the packages, which you installed, it also contains dependencies of your installed packages. 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). 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.

Ameba answered 19/1, 2022 at 16:37 Comment(2)
I was trying to figure out what package was giving me this problem and I found out that express-fileupload was the one. I deleted the version I had and updated it and it worked. Thx for the heads up either way, was a good oneFerreby
Glad that it helped, I had that kind of strange things during my experience as well)Ameba
A
0

Most probably this a version issue.

You can see the busboy version using:

npm list busboy

What worked for me was to uninstall busboy:

npm uninstall busboy

And then install an older version like 0.3.1

npm install [email protected]
Abuttal answered 5/4 at 7:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.