0

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

Aditya P
  • 19
  • 1
  • 9
  • 1
    As the error message tells you: You are trying to export class `FormControl` that you have not imported. Note that it's about the import/export sections of NgModule annotation and I can't see any reason why you want to export FormControl there. – Christoph Lütjen Jun 28 '20 at 17:25

3 Answers3

2

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.

Alin Bizau
  • 79
  • 1
  • 6
1

Your missing import FromControl from '@material-ui/core'

import FormControl from '@material-ui/core/FormControl';
// or
import { FormControl } from '@material-ui/core';

Refer : https://material-ui.com/api/form-control/

Bayu Dwiyan Satria
  • 986
  • 12
  • 28
0

I created a new Angular 9 Project and try to serve a prod build. The issue reoccurred.

In the end, instead of making changes to angular, I decided to just go with Angular 10 as a workaround. Fortunately, everything went smoothly in the new version.

Aditya P
  • 19
  • 1
  • 9