Javascript

node.js 报错 throw new TypeError(‘app.use() requires a middleware function‘)

本文主要是介绍node.js 报错 throw new TypeError(‘app.use() requires a middleware function‘),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
错误
C:\Users\Yang\Desktop\blog\node_modules\express\lib\application.js:210
    throw new TypeError('app.use() requires a middleware function')
    ^

TypeError: app.use() requires a middleware function
    at Function.use (C:\Users\Yang\Desktop\blog\node_modules\express\lib\application.js:210:11)
    at Object.<anonymous> (C:\Users\Yang\Desktop\blog\app.js:31:5)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:973:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47

原因

原因是因为 没有导出 module
(完全大意了,没有闪)
在 router.js 结尾中加入

module.exports = router;
这篇关于node.js 报错 throw new TypeError(‘app.use() requires a middleware function‘)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!