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

ความคิดเห็น • 42

  • @coreypowe7214
    @coreypowe7214 ปีที่แล้ว +2

    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

  • @luubinekel3894
    @luubinekel3894 2 ปีที่แล้ว +1

    thanks senior dev !

  • @chandrasatyannarayanayalam3858
    @chandrasatyannarayanayalam3858 3 หลายเดือนก่อน

    Really super video bro ......impressive

  • @sajeedsyed710
    @sajeedsyed710 ปีที่แล้ว +1

    Eventually I solved this error bcoz of you. Thank you

  • @warnercooler4488
    @warnercooler4488 ปีที่แล้ว +1

    That worked!! Thanks you so much! :)

  • @VinayKumar-fm6oc
    @VinayKumar-fm6oc ปีที่แล้ว +1

    Thanks for helping

  • @user-zu7ht9sm4d
    @user-zu7ht9sm4d ปีที่แล้ว

    I was having this kind of error since 2 days. By this i solved that silly mistake. Thank you.

  • @kshitizbathwal7509
    @kshitizbathwal7509 2 ปีที่แล้ว +2

    Thanks a lo! Exactly my error and you solved it!

  • @muxlisbek
    @muxlisbek ปีที่แล้ว +1

    Thenks ...

  • @taukoss
    @taukoss ปีที่แล้ว +1

    thank you bro you've save me a lot of time

  • @elhamsh7588
    @elhamsh7588 2 ปีที่แล้ว +1

    Great, so thanks for useful video

  • @drenzod
    @drenzod 5 หลายเดือนก่อน +1

    Thank you sir problem is solved

  • @modelno1528
    @modelno1528 2 ปีที่แล้ว +1

    what a beast, thenk you!

  • @atuloraon9610
    @atuloraon9610 6 หลายเดือนก่อน

    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.

  • @nevinharold
    @nevinharold 5 หลายเดือนก่อน

    Thank you!

  • @sivathmikachavali2026
    @sivathmikachavali2026 ปีที่แล้ว +1

    ❤❤❤

  • @yashkakade1441
    @yashkakade1441 2 ปีที่แล้ว +1

    thank you so much, it really solved my problem

  • @SR-mv2mf
    @SR-mv2mf ปีที่แล้ว +1

    Bro you solved my issue. Thanks bro

  • @alokshakya5570
    @alokshakya5570 ปีที่แล้ว +1

    thanks sir

  • @siddharthroy9930
    @siddharthroy9930 ปีที่แล้ว

    Koti koti dhanyawad

  • @haroldsurentu3451
    @haroldsurentu3451 2 ปีที่แล้ว +1

    thank you for sharing this

  • @diasoralbekov6465
    @diasoralbekov6465 2 ปีที่แล้ว +1

    thank you very much!!

  • @akshaykurhe8565
    @akshaykurhe8565 2 ปีที่แล้ว +1

    Thanks! this video is very usefull

  • @NelzonMamani
    @NelzonMamani ปีที่แล้ว +1

    // 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;

    • @crazzylearners9968
      @crazzylearners9968  ปีที่แล้ว

      is your express version latest?

    • @NelzonMamani
      @NelzonMamani ปีที่แล้ว +1

      @@crazzylearners9968 I realised body parser was the issue. We don't need body-parser. Yay

    • @teenageworrior1634
      @teenageworrior1634 10 หลายเดือนก่อน

      @@NelzonMamaniwhat do you mean ?? Please explain i the got same error

    • @biswabikashparida9691
      @biswabikashparida9691 9 หลายเดือนก่อน

      @@crazzylearners9968pls help i removed body parser too but the issue persists

  • @عبدالسلامالسميني
    @عبدالسلامالسميني 2 ปีที่แล้ว +1

    Thank you

  • @jsolutioncompany
    @jsolutioncompany ปีที่แล้ว +1

    Thanks bro 👍🏻

  • @jaswanthyadav7052
    @jaswanthyadav7052 2 ปีที่แล้ว +2

    thanks

  • @nicolasbaumtrog5671
    @nicolasbaumtrog5671 2 ปีที่แล้ว +1

    thanks

  • @shashankjangir3221
    @shashankjangir3221 ปีที่แล้ว

    thanks bro

  • @Human_Evolution-
    @Human_Evolution- 2 ปีที่แล้ว +1

    My imports are good and I get nearly the same error.

    • @crazzylearners9968
      @crazzylearners9968  2 ปีที่แล้ว

      Contact me on insta:
      instagram.com/crazzylearners?

  • @Mohit-fe5hx
    @Mohit-fe5hx 6 หลายเดือนก่อน

    Sir I am still getting same error

  • @mostafam3701
    @mostafam3701 10 หลายเดือนก่อน

    the error steal accure

  • @florianchazizi6483
    @florianchazizi6483 2 ปีที่แล้ว +1

    Thank you !

  • @dominoapunte
    @dominoapunte 2 ปีที่แล้ว +1

    thanks

  • @jeronimocardozo7404
    @jeronimocardozo7404 2 ปีที่แล้ว +1

    Thank you!

  • @joelhagg2580
    @joelhagg2580 2 ปีที่แล้ว +1

    Thanks!

  • @shaudamirpour5503
    @shaudamirpour5503 2 ปีที่แล้ว +1

    Thanks