簡體   English   中英

NodeJS - TypeError:Busboy 不是構造函數

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

所以,幾天前發生了一些事情,我的一個項目開始顯示以下錯誤:

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 的版本或錯誤中列出的任何可能導致此類問題的版本是否存在兼容性錯誤?

看,node_modules 不僅包含您安裝的包,它還包含已安裝包的依賴項。 因此,一個好的做法是將鎖定文件用作 package-lock.json,這將鎖定每個包的版本,並且每次運行npm install它都會安裝精確的鎖定版本(更准確地說 - 使用npm ci 因此,在這種情況下,我看到您的一個軟件包已更新,或者“busboy”package 已更新,並且在您運行安裝腳本后,它為您帶來了涉及此錯誤的更新的 package(或軟件包)。

只是為可能感到困惑的人添加另一個答案。 Busboy 導出的是 function 而不是 class。 因此,不需要使用 new 關鍵字來創建 Busboy 的實例。

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

這個答案只是為了讓那些因多個示例和教程而感到困惑的人更加清楚。 如果有任何改進,請提出改進建議。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM