Skip to content
Advertisement

TypeError: expressJwt is not a function

I’m trying to write middleware for user authorization in my app. I use this function to check if a route requires being sign in. The code is as follows:

JavaScript

However, I get the following error:

JavaScript

What could be the problem? None of the other answers seem to be helpful.

Advertisement

Answer

With the curly brackets

JavaScript

you are trying to do object destructuring, which looks for a field named expressJwt in the object exported by express-jwt module. But according to the error message that object doesn’t have such field.

As per express-jwt‘s documentation, you don’t need destructuring but to simply assign the exported object into a variable, so try the following form (without curly brackets):

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement