你知道为什么会出现错误消息“TypeError:expressJwt is not a function”吗?怎么解决?

问题描述 投票:0回答:1
const expressJwt = require('express-jwt')

function authJwt() {
    const secret = process.env.secret
    return expressJwt({
        secret,
        algorithms: ['HS256']
    })
}

module.exports = authJwt
C:\code-wldn\final-project\wldn-api\helpers\jwt.js:5
return expressJwt({
       ^

TypeError: expressJwt is not a function
    at authJwt (C:\code-wldn\final-project\wldn-api\helpers\jwt.js:5:12)
    at Object.<anonymous> (C:\code-wldn\final-project\wldn-api\app.js:18:9)

enter image description here

尽快...我尝试通过确保正确导入express-jwt并将其用作jwt.js文件中的函数来解决错误消息“TypeError:expressJwt不是函数”。我预计该错误能够得到解决,从而允许应用程序运行而不会出现任何与expressJwt相关的问题。然而,尽管我尝试解决该错误,但该错误仍然存在。

javascript node.js authorization token express-jwt
1个回答
0
投票

根据express-jwt文档所说,应该使用以下语法导入:

var { expressjwt } = require("express-jwt");
© www.soinside.com 2019 - 2024. All rights reserved.