0

I am new to Angular environment and creating a project using Bootstrap 4 + angular material. I am using "material.module.ts" to import-export all required material components.

When I am running the application with "ng serve" command, it is not showing any error and working smoothly. Bit when I build using --aot parameter or build for production (ng build --prod) it is giving error:

    ERROR in Illegal State: referring to a type without a variable {"filePath":"D:/ff/node_modules/@angular/material/form-field/typings/index.d.ts","name":"MatFormField","members":[]} 

angular build with --prod parameter fails but able to run the application

Below is the output for ng --version:

    Angular CLI: 8.3.0
    Node: 12.7.0
    OS: win32 x64
    Angular: 8.2.3
    ... animations, common, compiler, compiler-cli, core, forms
    ... language-service, platform-browser, platform-browser-dynamic
    ... router

    Package                           Version
    -----------------------------------------------------------
    @angular-devkit/architect         0.803.0
    @angular-devkit/build-angular     0.802.2
    @angular-devkit/build-optimizer   0.802.2
    @angular-devkit/build-webpack     0.802.2
    @angular-devkit/core              8.3.0
    @angular-devkit/schematics        8.3.0
    @angular/cdk                      8.1.3
    @angular/cli                      8.3.0
    @angular/material                 8.1.3
    @ngtools/webpack                  8.2.2
    @schematics/angular               8.3.0
    @schematics/update                0.803.0
    rxjs                              6.4.0
    typescript                        3.5.3
    webpack  

I tried npm update,npm audit fix, ng update.. but none of them fixed the issue. Same issue in my mac and windows machine

1 Answers1

0

This is possibly because you haven't imported MatFormField in your FeatureModule. If you are using <mat-form-field> in any of your child components make sure you are importing it in module.

import { MatFormFieldModule } from '@angular/material/form-field';

@NgModule({
    declarations: [ ... ],
    imports: [
        CommonModule,
        MatFormFieldModule,
        ...    
    ]
})
export class FeatureModule { }
Suroor Ahmmad
  • 1,110
  • 4
  • 23
  • 33