Search code examples
angularangular-materialangular-formsng-build

Angular serve works in dev but fails in prod due to a form related import


I get the following error when I run a prod build on my Angular 9 app.

enter image description here

ERROR in Can't export value FormControl in from MaterialModule in as it was neither declared nor imported!

I have imported FormsModule and ReactiveForms Module in my App Module and a shared Module called


// Angular Material Components
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule }   from '@angular/forms';
import { ReactiveFormsModule, FormControl } from '@angular/forms';

const MatModules = [

  ReactiveFormsModule,
  FormControl,
  FormsModule,
]

@NgModule({
  declarations: [ ],
  imports : [
    FormsModule,
    ReactiveFormsModule
   ],
  exports : [ MatModules ]
})

export class MaterialModule { }

Kindly let me know what I am missing.

Thanks!

Warm Regards, Adi


Solution

  • My question is: why you want export FormControl? You don't need import/export FormControl, you just need to import ReactiveFormsModule and you will be able to use FormControl.