ERROR in node_modules/@auth0/angular-jwt/lib/jwtoptions.token.d.ts(2,50): error TS2304: Cannot find name 'unknown'

末鹿安然 提交于 2021-01-04 08:16:29

问题


When compiling my angular project, I get the following error. I deleted my node_modules file and reinstalled it still didn't work.

ERROR in node_modules/@auth0/angular-jwt/lib/jwtoptions.token.d.ts(2,50): error TS2304: Cannot find name 'unknown'.

package.json

{
  "name": "ArinhureWeb",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build:ssr": "ng run ArinhureWeb:server:dev",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "6.1.10",
    "@angular/common": "6.1.10",
    "@angular/compiler": "6.1.10",
    "@angular/core": "6.1.10",
    "@angular/forms": "6.1.10",
    "@angular/http": "6.1.10",
    "@angular/platform-browser": "6.1.10",
    "@angular/platform-browser-dynamic": "6.1.10",
    "@angular/platform-server": "6.1.10",
    "@angular/router": "6.1.10",
    "@auth0/angular-jwt": "^5.0.1",
    "@nguniversal/module-map-ngfactory-loader": "6.0.0",
    "aspnet-prerendering": "^3.0.1",
    "bootstrap": "^4.1.3",
    "chart.js": "^2.9.3",
    "core-js": "^2.5.4",
    "jquery": "3.3.1",
    "popper.js": "^1.14.3",
    "rxjs": "6.0.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.0",
    "@angular/cli": "~6.0.0",
    "@angular/compiler-cli": "6.1.10",
    "@angular/language-service": "^6.0.0",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~1.4.2",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "typescript": "~2.7.2"
  },
  "optionalDependencies": {
    "node-sass": "^4.9.3",
    "protractor": "~5.4.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
  }
}

回答1:


I had this issue and found a solution. I am currently running Angular 6 and installed version 4.2 after looking at the documentation that says "For Angular v6+ to v9, use @auth0/angular-jwt v4". I got the same error:

fail: Microsoft.AspNetCore.SpaServices[0] node_modules/@auth0/angular-jwt/lib/jwtoptions.token.d.ts(2,50): error TS2304: Cannot find name 'unknown'.

I opened the jwtoptions.token.d.ts file in node_modules and it is a simple two line file:

import { InjectionToken } from '@angular/core';
export declare const JWT_OPTIONS: InjectionToken<unknown>;

'unknown' is a new type that was introduced in typescript 3 and Angular 6.0.9 is dependent on typescript ~2.7. Additionally, the 4.2 version of @auth0/angular-jwt dependencies target Angular 7.1+ as you can see from this npm warning:

npm WARN @auth0/angular-jwt@4.2.0 requires a peer of @angular/common@>=7.1.0 but none is installed. You must install peer dependencies yourself.

I think this package is running into issues supporting older versions of Angular. I simply downgraded to the version @auth0/angular-jwt@3.0.1 and no longer have errors.

Here is my package.json:

  "dependencies": {
    "@angular/animations": "6.0.9",
    "@angular/cdk": "^6.4.7",
    "@angular/common": "6.0.9",
    "@angular/compiler": "6.0.9",
    "@angular/core": "6.0.9",
    "@angular/forms": "6.0.9",
    "@angular/http": "6.0.9",
    "@angular/material": "^6.4.7",
    "@angular/platform-browser": "6.0.9",
    "@angular/platform-browser-dynamic": "6.0.9",
    "@angular/router": "6.0.9",
    "@auth0/angular-jwt": "3.0.1",
    "@ng-idle/core": "^6.0.0-beta.3",
    "@ng-idle/keepalive": "^6.0.0-beta.3",
    "angular2-moment": "^1.9.0",
    "bootstrap": "3.3.2",
    "bootstrap-tree": "1.2.0",
    "chart.js": "2.0.2",
    "core-js": "2.4.1",
    "font-awesome": "4.7.0",
    "formvalidation": "0.6.2-dev",
    "jquery": "1.11.2",
    "jquery-match-height": "0.7.2",
    "jquery-sparkline": "2.3.2",
    "jstree": "3.3.4",
    "ngx-bootstrap": "3.0.1",
    "noty": "2.4.1",
    "pdfmake-client": "1.0.0",
    "primeicons": "1.0.0-beta.9",
    "primeng": "6.0.0",
    "rxjs": "6.0.0",
    "rxjs-compat": "6.2.2",
    "sortablejs": "1.6.0",
    "webpack": "^4.4.0",
    "zone.js": "0.8.26"
  },
  "devDependencies": {
    "@angular/cli": "6.1.4",
    "@angular/compiler-cli": "6.0.9",
    "@angular/language-service": "6.0.9",
    "@angular-devkit/build-angular": "0.6.7",
    "@angular-devkit/core": "0.5.11",
    "@types/jasmine": "2.8.3",
    "@types/jasminewd2": "2.0.2",
    "@types/node": "6.0.60",
    "codelyzer": "4.0.1",
    "jasmine-core": "2.8.0",
    "jasmine-spec-reporter": "4.2.1",
    "karma": "2.0.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "1.2.1",
    "karma-jasmine": "1.1.0",
    "karma-jasmine-html-reporter": "0.2.2",
    "protractor": "5.1.2",
    "ts-node": "3.2.0",
    "tslint": "5.9.1",
    "typescript": "2.7.2"
  },


来源:https://stackoverflow.com/questions/63400257/error-in-node-modules-auth0-angular-jwt-lib-jwtoptions-token-d-ts2-50-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!