使用“发生未处理的异常:NGCC 失败”编译 Angular 项目

der*_*e23 20 angular-material angular

我试图编译我的项目,但出现错误:

Error: Error on worker #3: Error: No typings declaration can be found for the referenced NgModule class in static withConfig(configOptions, 
        // tslint:disable-next-line:max-line-length
        breakpoints = []) {
            return {
                ngModule: FlexLayoutModule,
                providers: configOptions.serverLoaded ?
                    [
                        { provide: LAYOUT_CONFIG, useValue: Object.assign(Object.assign({}, DEFAULT_CONFIG), configOptions) },
                        { provide: BREAKPOINT, useValue: breakpoints, multi: true },
                        { provide: SERVER_TOKEN, useValue: true },
                    ] : [
                    { provide: LAYOUT_CONFIG, useValue: Object.assign(Object.assign({}, DEFAULT_CONFIG), configOptions) },
                    { provide: BREAKPOINT, useValue: breakpoints, multi: true },
                ]
            };
        }.
Run Code Online (Sandbox Code Playgroud)

我使用了 ng add @angular/material并且出现npm install @angular/flex-layout@latest --save了这个错误。

直到现在我尝试过:

  • 多次重新安装 flexLayot。
  • 删除 node_modules 并再次安装。

我的依赖项如下所示:

"dependencies": {
    "@angular/animations": "^9.1.11",
    "@angular/cdk": "^9.2.4",
    "@angular/common": "~9.1.11",
    "@angular/compiler": "~9.1.11",
    "@angular/core": "~9.1.11",
    "@angular/flex-layout": "^10.0.0-beta.32",
    "@angular/forms": "~9.1.11",
    "@angular/material": "^9.2.4",
    "@angular/platform-browser": "~9.1.11",
    "@angular/platform-browser-dynamic": "~9.1.11",
    "@angular/router": "~9.1.11",
    "rxjs": "~6.5.5",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  }
Run Code Online (Sandbox Code Playgroud)

有人知道这可能是错的吗?

我的 app.module.ts

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    SharedModule,
    HomeModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)

但我将 Flex 添加到共享模块,所以我也会粘贴 shared.module.ts


@NgModule({
  declarations: [],
  imports: [
    CommonModule,
    FlexLayoutModule
  ],
  exports: [
    FlexLayoutModule
  ]
})
export class SharedModule { }

Run Code Online (Sandbox Code Playgroud)

jpa*_*vel 42

切换回FlexLayout 9.0.0-beta.31. 根据其更新日志,您使用的版本“(...) 添加了对 Angular v10 和 Angular CDK v10 的支持。”

@angular'sModuleWithProviders不是@angular 9.xx 中的泛型,而是@angular 10 rc.x 中的泛型。FlexLayout x.x.x-beta.32开始使用通用版本 ( ModuleWithProviders<T>),因此它不再适用于 @angular 版本 < 10。您需要切换回FlexLayout 9.0.0-beta.31.

在你的 package.json 中,替换"@angular/flex-layout": "^10.0.0-beta.32"for "@angular/flex-layout": "~9.0.0-beta.31"npm install再次运行(或干脆npm install @angular/flex-layout@9.0.0-beta.31"


小智 12

通过命令重新安装flex-layout

npm i @angular/flex-layout@9.0.0-beta.31