Search code examples
angularangular-cliangular-formsangular10angular-ivy

'FormsModule' does not appear to be an NgModule class


I am trying to import the FormsModule but i get this error 'FormsModule' does not appear to be an NgModule class. here is my code

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms'; // Add this import

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule 
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

and my package.json this

"dependencies": {
    "@angular/animations": "~10.1.3",
    "@angular/common": "^10.1.6",
    "@angular/compiler": "^10.1.6",
    "@angular/core": "^10.1.6",
    "@angular/fire": "^6.1.0",
    "@angular/forms": "^10.1.6",
    "@angular/platform-browser": "~10.1.3",
    "@angular/platform-browser-dynamic": "~10.1.3",
    "@angular/router": "~10.1.3",
    "firebase": "^8.0.1",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0",
    "zone.js": "~0.10.2"
  }

I did search to similar question here but didnt help me i did try to unistall forms and install again also didnt work


Solution

  • Add this to the package.json scripts object.

    "scripts": {
      ...
      "postinstall": "ngcc",
      ...
    }
    

    So that the packages are all compatible with Ivy Engine (default engine for angular 10).

    Angular 10 Libraries and IVY/ngcc Compatibility