【问题标题】:angular/cdk giving lots of build errorsangular/cdk 给出了很多构建错误
【发布时间】:2020-09-30 15:21:17
【问题描述】:

我正在执行拖放实现并为此安装了 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 包之间存在一些版本不兼容,可能是核心/通用等,我也尝试过。

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

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

angular-cli: 1.0.0-beta.28.3

节点:12.18.0

操作系统:win32 x64

@angular/cdk: 9.2.4

@angular/common: 2.4.10

@angular/编译器:2.4.10

@angular/core: 2.4.10

@angular/forms: 2.4.10

@angular/http:2.4.10

@angular/platform-b​​rowser: 2.4.10

@angular/platform-b​​rowser-dynamic: 2.4.10

@angular/路由器:3.4.10

@angular/compiler-cli: 2.4.10

【问题讨论】:

    标签: angular angular-material node-modules angular-cdk npm-start


    【解决方案1】:

    @angular/cdk@9.2.4 不能与@angular/core@2.x.x 一起使用。您需要 @angular@9.x.x 才能正常工作。

    【讨论】:

    • 感谢您的回复。请检查我在上面编辑中使用的当前版本。
    猜你喜欢
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多