TypeError: Router.use() requires a middleware function but got a Object | Node Js error
ฝัง
- เผยแพร่เมื่อ 18 ก.ย. 2024
- #nodejserror #expresserror #nodejs #express #error #webdevelopement #jserror #javascript
#TypeErrorRouteruserequiresamiddlewarefunctionbutgotaObjectNodeJserror
Instagram: www.instagram....
github: github.com/dat...
Complete Error:
throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
^
TypeError: Router.use() requires a middleware function but got a Object
at Function.use (E:\python utube error\js errors
ode_modules\express\lib
outer\index.js:458:13)
at Function.anonymous (E:\python utube error\js errors
ode_modules\express\lib\application.js:220:21)
at Array.forEach (anonymous)
at Function.use (E:\python utube error\js errors
ode_modules\express\lib\application.js:217:7)
at Object.anonymous (E:\python utube error\js errors\server.js:5:5)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
[nodemon] app crashed - waiting for file changes before starting...
Thanks for explaining this one. I typed "module.export" instead of "module.exports" which ignored the command and throw the error as mentioned here. Again thanks
thanks senior dev !
Really super video bro ......impressive
Eventually I solved this error bcoz of you. Thank you
That worked!! Thanks you so much! :)
Thanks for helping
I was having this kind of error since 2 days. By this i solved that silly mistake. Thank you.
Thanks a lo! Exactly my error and you solved it!
Thenks ...
thank you bro you've save me a lot of time
Great, so thanks for useful video
Thank you sir problem is solved
what a beast, thenk you!
For those of you still not solved it is a typescript thing use
import router from '/path/to/router'
Everything was right for me but it is a ts thing.
Thank you!
❤❤❤
thank you so much, it really solved my problem
Bro you solved my issue. Thanks bro
thanks sir
Koti koti dhanyawad
thank you for sharing this
thank you very much!!
Thanks! this video is very usefull
// in my case the exact problem is not solved even when I am correctly exporting router, any ideas? cheers
const express = require('express');
const { authenticate, authorize } = require('../middlewares/auth');
const { validateUserData } = require('../middlewares/validation');
const { createUser, getUsers, getUser, updateUser, deleteUser } = require('../controllers/userController');
const router = express.Router();
router.post('/', validateUserData, createUser);
router.get('/', authenticate, authorize(['admin']), getUsers);
router.get('/:id', authenticate, getUser);
router.patch('/:id', authenticate, authorize(['admin']), updateUser);
router.delete('/:id', authenticate, authorize(['admin']), deleteUser);
module.exports = router;
is your express version latest?
@@crazzylearners9968 I realised body parser was the issue. We don't need body-parser. Yay
@@NelzonMamaniwhat do you mean ?? Please explain i the got same error
@@crazzylearners9968pls help i removed body parser too but the issue persists
Thank you
Thanks bro 👍🏻
thanks
thanks
thanks bro
My imports are good and I get nearly the same error.
Contact me on insta:
instagram.com/crazzylearners?
Sir I am still getting same error
the error steal accure
Thank you !
thanks
Thank you!
Thanks!
Thanks