Angular &引用;jwt“解码”网页“导入”模块“11”不是函数;尝试使用jwt decode npm软件包解码令牌时离子/角度/电容器出错

Angular &引用;jwt“解码”网页“导入”模块“11”不是函数;尝试使用jwt decode npm软件包解码令牌时离子/角度/电容器出错,angular,ionic-framework,npm,angular2-services,capacitor,Angular,Ionic Framework,Npm,Angular2 Services,Capacitor,我已经使用jwt解码包对接收到的令牌进行解码 import * as jwt_decode from "jwt-decode"; 收到有效令牌后,我们将其称为variabletok 关于解码令牌 var tokenDecoded = jwt_decode(tok) 我得到以下错误 Unhandled Promise rejection: jwt_decode__WEBPACK_IMPORTED_MODULE_11__ is not a function ; Zone: &

我已经使用jwt解码包对接收到的令牌进行解码

import * as jwt_decode from "jwt-decode";
收到有效令牌后,我们将其称为variabletok

关于解码令牌

var tokenDecoded = jwt_decode(tok)
我得到以下错误

Unhandled Promise rejection: jwt_decode__WEBPACK_IMPORTED_MODULE_11__ is not a function ; Zone: <root> ; Task: Promise.then ; Value: TypeError: jwt_decode__WEBPACK_IMPORTED_MODULE_11__ is not a function
at AuthService.<anonymous> (auth.service.ts:193)
at Generator.next (<anonymous>)
at fulfilled (tslib.es6.js:71)
at ZoneDelegate.invoke (zone-evergreen.js:359)
at Zone.run (zone-evergreen.js:124)
at zone-evergreen.js:855
at ZoneDelegate.invokeTask (zone-evergreen.js:391)
at Zone.runTask (zone-evergreen.js:168)
at drainMicroTaskQueue (zone-evergreen.js:559) TypeError: jwt_decode__WEBPACK_IMPORTED_MODULE_11__ is not a function
at AuthService.<anonymous> (http://localhost:8100/main.js:1431:32)
at Generator.next (<anonymous>)
at fulfilled (http://localhost:8100/vendor.js:218136:58)
at ZoneDelegate.invoke (http://localhost:8100/polyfills.js:3397:26)
at Zone.run (http://localhost:8100/polyfills.js:3162:43)
at http://localhost:8100/polyfills.js:3893:36
at ZoneDelegate.invokeTask (http://localhost:8100/polyfills.js:3429:31)
at Zone.runTask (http://localhost:8100/polyfills.js:3206:47)
at drainMicroTaskQueue (http://localhost:8100/polyfills.js:3597:35)
未处理承诺拒绝:jwt\u解码\u网页包\u导入的\u模块\u 11\u不是一个函数;区域:;任务:承诺;值:TypeError:jwt\u解码\u网页包\u导入的\u模块\u 11\u不是函数
随时为您服务。(授权服务ts:193)
在Generator.next()处
完成时(tslib.es6.js:71)
在ZoneDelegate.invoke(zone evergreen.js:359)
在Zone.run(Zone evergreen.js:124)
常青区。js:855
在ZoneDelegate.invokeTask(zone everyver.js:391)
在Zone.runTask(Zone everyver.js:168)
在drainMicroTaskQueue(zone evergreen.js:559)中,类型错误:jwt_解码_网页_导入的_模块_11_不是函数
随时为您服务。(http://localhost:8100/main.js:1431:32)
在Generator.next()处
至少(http://localhost:8100/vendor.js:218136:58)
在ZoneDelegate.invoke(http://localhost:8100/polyfills.js:3397:26)
在Zone.run(http://localhost:8100/polyfills.js:3162:43)
在http://localhost:8100/polyfills.js:3893:36
在ZoneDelegate.invokeTask(http://localhost:8100/polyfills.js:3429:31)
在Zone.runTask(http://localhost:8100/polyfills.js:3206:47)
在drainMicroTaskQueue(http://localhost:8100/polyfills.js:3597:35)

我在我的ionic/angular/capacitor应用程序中这样做,用于解码jwt令牌:

npm安装@types/jwt解码

添加导入:

从“jwt解码”导入jwt_解码

在您的代码中(tok是您要解码的令牌):

const-tokenDecoded=jwt\u解码(tok)