Skip to content
Discussion options

You must be logged in to vote

Router.use() requires a middleware function but got an Object is a runtime error: Express received something that is not a function. The setReqUser source you posted is a function, so the bug is almost always at the call site or in the module interop, not in the JWT logic.

1. You called the middleware instead of passing it

setReqUser is async. Calling it returns a Promise, and a Promise is an object:

// wrong — passes a Promise
app.use(setReqUser())

// right — passes the function
app.use(setReqUser)

This is the most common cause with async middleware.

2. You mounted the module object (CJS / default export)

// CommonJS: this is `{ default: [Function] }`, not the function
const setReqUser = …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by decompilexyz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #6283 on January 18, 2025 19:59.