JWT Helper服务在Angular 10中引发错误

问题描述

我正在使用Angular 10和最新的JWT Helper服务。但是该应用无法编译。

错误状态如下: ERROR in node_modules/@auth0/angular-jwt/lib/jwthelper.service.d.ts 我已经搜索了类似的问题,但是找不到答案。这是第一次发生这种情况。

控制台还会报告以下内容This likely means that the library (@auth0/angular-jwt) which declares JwtHelperService has not been processed correctly by ngcc,or is not compatible with Angular Ivy. Check if a newer version of the library is available,and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy

我已经删除了节点软件包文件夹,做了npm i错误仍然存​​在。这意味着Helper Service与Angular 10不兼容吗?

我的包裹JSON:

 "dependencies": {
    "@angular/animations": "~10.0.4","@angular/cdk": "^10.2.3","@angular/common": "~10.0.4","@angular/compiler": "~10.0.4","@angular/core": "~10.0.4","@angular/forms": "~10.0.4","@angular/localize": "~10.0.4","@angular/material": "^10.2.3","@angular/platform-browser": "~10.0.4","@angular/platform-browser-dynamic": "~10.0.4","@angular/router": "~10.0.4","@auth0/angular-jwt": "^5.0.1","@ng-bootstrap/ng-bootstrap": "^7.0.0","bootstrap": "^4.5.0","ng2-validation": "^4.2.0","rxjs": "~6.5.5","tslib": "^2.0.0","zone.js": "~0.10.3"
  },"devDependencies": {
    "@angular-devkit/build-angular": "~0.1000.3","@angular/cli": "~10.0.3","@angular/compiler-cli": "~10.0.4","@types/node": "^12.11.1","@types/jasmine": "~3.5.0","@types/jasminewd2": "~2.0.3","codelyzer": "^6.0.0","jasmine-core": "~3.5.0","jasmine-spec-reporter": "~5.0.0","karma": "~5.0.0","karma-chrome-launcher": "~3.1.0","karma-coverage-istanbul-reporter": "~3.0.2","karma-jasmine": "~3.3.0","karma-jasmine-html-reporter": "^1.5.0","protractor": "~7.0.0","ts-node": "~8.3.0","tslint": "~6.1.0","typescript": "~3.9.5"
  }

任何帮助都会被重视

解决方法

这对我有用-stackblitz example。如果您在点击按钮后查看“网络”标签,则会按预期添加“授权请求”标头。

根据库-如果为根导入JWT模块,它将自动添加授权标头。 JWT Helper服务仅供独立使用-https://www.npmjs.com/package/@auth0/angular-jwt

查看stackblitz链接,了解我如何在angular应用中使用它

,

使用以下命令更新tsconfig.app.json:

“ angularCompilerOptions”:{ “ enableIvy”:是 }