angular/cdk 出现大量构建错误

angular/cdk giving lots of build errors

我正在执行拖放操作并为此安装了 angular cdk。但是在 运行 npm start 上,我遇到了无数错误,所有错误都只与 cdk 节点模块有关。

下面是package.json:

{
  "name": "test-proj",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/cdk": "^9.2.4",
    "@angular/common": "^2.4.10",
    "@angular/compiler": "^2.3.1",
    "@angular/core": "^2.4.10",
    "@angular/forms": "^2.3.1",
    "@angular/http": "^2.3.1",
    "@angular/platform-browser": "^2.3.1",
    "@angular/platform-browser-dynamic": "^2.4.10",
    "@angular/router": "^3.3.1",
    "core-js": "^2.4.1",
    "rxjs": "^5.0.1",
    "ts-helpers": "^1.1.1",
    "tslib": "^2.0.0",
    "zone.js": "^0.7.2"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^2.3.1",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.28.3",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "^5.0.9",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "^7.0.0",
    "ts-node": "1.2.1",
    "tslint": "^5.20.1",
    "typescript": "~2.0.3"
  }
}

错误如下:

> `ERROR in ~/node_modules/@angular/cdk/coercion/array.d.ts (10,60): '='
> expected.
> 
> ERROR in ~j/node_modules/@angular/cdk/coercion/array.d.ts (10,75): '{'
> or ';' expected.
> 
> ERROR in ~/node_modules/@angular/cdk/coercion/array.d.ts (10,40): A
> parameter initializer is only allowed in a function or constructor
> implementation.
> 
> ERROR in ~/node_modules/@angular/cdk/coercion/array.d.ts (10,51):
> Cannot find name 'readonly'.
> 
> ERROR in ~/node_modules/@angular/cdk/coercion/array.d.ts (10,66):
> Cannot find name 'readonly'.
> 
> ERROR in ~/node_modules/@angular/cdk/coercion/array.d.ts (10,75):
> Cannot find name 'T'.
> 
> ERROR in ~/node_modules/@angular/cdk/coercion/element.d.ts (13,56):
> Type 'ElementRef' is not generic.
> 
> ERROR in ~/node_modules/@angular/cdk/bidi/dir-document-token.d.ts
> (8,10): Module '"~/node_modules/@angular/core/index"' has no exported
> member 'InjectionToken'.
> 
> ERROR in ~/node_modules/@angular/cdk/bidi/dir.d.ts (26,9): An accessor
> cannot be declared in an ambient context.
> 
> ERROR in ~/node_modules/@angular/cdk/bidi/dir.d.ts (27,9): An accessor
> cannot be declared in an ambient context.
> 
> ERROR in ~/node_modules/@angular/cdk/bidi/dir.d.ts (29,9): An accessor
> cannot be declared in an ambient context.
> 
> ERROR in ~/node_modules/@angular/cdk/collections/selection-model.d.ts
> (24,9): An accessor cannot be declared in an ambient context.
> 
> ERROR in
> ~/node_modules/@angular/cdk/platform/features/passive-listeners.d.ts
> (19,66): Cannot find name 'AddEventListenerOptions'.
> 
> ERROR in
> ~/node_modules/@angular/cdk/platform/features/passive-listeners.d.ts
> (19,92): Cannot find name 'AddEventListenerOptions'.
> 
> ERROR in ~/node_modules/@angular/cdk/scrolling/scrollable.d.ts
> (13,17): ']' expected.

…… 还有很多这样的.. ......`

错误似乎是语法上的,所以我假设 cdk 和其他 angular 包之间存在一些版本不兼容,可能是 core/common 等,我也试过了。

我也尝试安装 material,但结果相同。

编辑: 我目前使用的版本是:

angular-cli: 1.0.0-beta.28.3

node: 12.18.0

os: win32 x64

@angular/cdk: 9.2.4

@angular/common: 2.4.10

@angular/compiler: 2.4.10

@angular/core: 2.4.10

@angular/forms: 2.4.10

@angular/http: 2.4.10

@angular/platform-browser: 2.4.10

@angular/platform-browser-dynamic: 2.4.10

@angular/router: 3.4.10

@angular/compiler-cli: 2.4.10

@angular/cdk@9.2.4 不适用于 @angular/core@2.x.x。您需要 @angular@9.x.x 才能正常工作。