【问题标题】:JWT Helper service throws error in Angular 10JWT Helper 服务在 Angular 10 中引发错误
【发布时间】:2021-01-21 18:24:28
【问题描述】:

我正在使用 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"
  }

任何帮助将不胜感激

【问题讨论】:

    标签: angular compilation ivy jwt-auth


    【解决方案1】:

    这对我有用 - stackblitz example。如果您在单击按钮时查看网络选项卡,它会按预期添加授权请求标头。

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

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

    【讨论】:

      【解决方案2】:

      更新 tsconfig.app.json 为:

      "angularCompilerOptions": { “启用常春藤”:真 }

      【讨论】:

      • 控制台Angular JIT compilation failed: '@angular/compiler' not loaded!仍然出错
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-10
      • 2021-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-23
      相关资源
      最近更新 更多