Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4.4.0-4.4.2 production build throwing "No provider for NgForm!" error

Tags:

angular

I am getting

"No Provider for e!"

error when running my Angular application in production mode. On development mode it is working fine. I am getting following error:

enter image description here

I tried with ng build -aot Now getting error

"Error: No provider for NgForm!"

Does anybody have any idea how to fix it?

Following is the package.json file I am using:

{
  "name": "app-web",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "hmr": "ng serve --hmr -e=hmr",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.2.4",
    "@angular/common": "^4.2.4",
    "@angular/compiler": "^4.2.4",
    "@angular/core": "^4.2.4",
    "@angular/forms": "^4.2.4",
    "@angular/http": "^4.2.4",
    "@angular/platform-browser": "^4.2.4",
    "@angular/platform-browser-dynamic": "^4.2.4",
    "@angular/router": "^4.2.4",
    "@types/bootstrap-datepicker": "0.0.10",
    "@types/d3": "^4.10.0",
    "@types/jquery": "^3.2.11",
    "bootstrap": "^3.3.7",
    "bootstrap-datepicker": "^1.7.1",
    "core-js": "^2.4.1",
    "d3": "^4.10.2",
    "file-saver": "^1.3.3",
    "jquery": "^3.2.1",
    "moment": "^2.18.1",
    "ng-bootstrap-form-validation": "^1.0.3",
    "ng2-ckeditor": "^1.1.9",
    "ngx-bootstrap": "^1.8.1",
    "ngx-malihu-scrollbar": "^1.2.1",
    "rxjs": "^5.4.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.3.0",
    "@angular/compiler-cli": "^4.2.4",
    "@angular/language-service": "^4.2.4",
    "@angularclass/hmr": "^2.1.3",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.1.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3"
  }
}
like image 263
Rajesh Kumar Avatar asked Sep 19 '17 14:09

Rajesh Kumar


2 Answers

I resolved it like this:

import { FormsModule, NgForm } from '@angular/forms';
import { myComponent } from './my.component';
describe('myComponent', () => {
let component: myComponent;
let fixture: ComponentFixture<EmailInputsComponent>;
beforeEach(async(() => {
    TestBed.configureTestingModule({
        imports: [FormsModule],
        declarations: [myComponent],
        providers: [NgForm] // <- LOOK AT ME I AM A PROVIDER!!!
like image 74
mruanova Avatar answered Nov 13 '22 13:11

mruanova


Update:

Angular v4.4.3 should fix the issue

Previous version:

I assume you're using angular 4.x version.

It's known issue. Wait till new angular version is published or set angular version to 4.3.6

See also

  • https://github.com/angular/angular/issues/19219
like image 35
yurzui Avatar answered Nov 13 '22 13:11

yurzui