title: Angular 5 Error (Angular CLI) - Can't run ng build --prod
body: <p><a href="https://i.stack.imgur.com/rXdT2.png" rel="nofollow noreferrer">Angular Error message</a>  </p>
  
  <p>I just can't figure this one out. If I run this locally via ng serve and ng build, it works fine. But when I run ng build --prod, it fails with a "Error in ./scr/main.ts. Module not found: Error Can'r resolve './app/app.module.ngFacttory in ...ClientApp\src"</p>
  
  <p>I've supplied my main.ts/.angular-cli.json/package.json/app.module.ts.</p>
  
  <p>What am I missing??</p>
  
  <pre><code>//main.ts
  import { enableProdMode } from '@angular/core';
  import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
  
  import { AppModule } from './app/app.module';
  import { environment } from './environments/environment';
  
  export function getBaseUrl() {
    return document.getElementsByTagName('base')[0].href;
  }
  
  const facilitys = [
    { provide: 'BASE_URL', useFactory: getBaseUrl, deps: [] }
  ];
  
  if (environment.production) {
    enableProdMode();
  }
  
  platformBrowserDynamic(facilitys).bootstrapModule(AppModule)
    .catch(err =&gt; console.log(err));
  
  //app.module.ts
  import { BrowserModule } from '@angular/platform-browser';
  import { NgModule } from '@angular/core';
  import { FormsModule } from '@angular/forms';
  import { HttpClientModule } from '@angular/common/http';
  import { RouterModule } from '@angular/router';
  import { HttpModule } from '@angular/http';
  import { ReactiveFormsModule } from '@angular/forms';
  import { CommonModule} from "@angular/common";
  
  import { AppComponent } from './app.component';
  import { NavMenuComponent } from './nav-menu/nav-menu.component';
  import { HomeComponent } from './home/home.component';
  
  import { MentalHealthService } from './service/mental.health.service';
  import { AppRoutingModule } from './app-routing.module';
  import { ProviderModule } from "./provider/provider.module";
  import { FacilityModule } from "./facility/facility.module";
  import { VendorModule } from "./vendor/vendor.module";
  
  
  
  @NgModule({
    declarations: [
      AppComponent,
      NavMenuComponent,
      HomeComponent
    ],
    imports: [
      BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }),
      HttpClientModule,
      FormsModule,
      HttpModule,
      ReactiveFormsModule,
      ProviderModule,
      FacilityModule,
      VendorModule,
      AppRoutingModule,
      CommonModule
    ],
    exports: [
      CommonModule,
      FormsModule],
    providers: [MentalHealthService],
    bootstrap: [AppComponent]
  })
  export class AppModule { }
  
  //Angular-cli.json
  {
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "project": {
      "name": "AngularTemplate"
    },
    "apps": [
      {
        "root": "src",
        "outDir": "dist",
        "assets": [
          "assets"
        ],
        "index": "index.html",
        "main": "main.ts",
        "polyfills": "polyfills.ts",
        "test": "test.ts",
        "tsconfig": "tsconfig.app.json",
        "testTsconfig": "tsconfig.spec.json",
        "prefix": "app",
        "styles": [
          "styles.css",
          "../node_modules/bootstrap/dist/css/bootstrap.min.css",
          "../node_modules/font-awesome/css/font-awesome.css"
  
        ],
        "scripts": [
          "../node_modules/jquery/dist/jquery.min.js",
          "../node_modules/popper.js/dist/umd/popper.min.js",
          "../node_modules/bootstrap/dist/js/bootstrap.min.js"
  
        ],
        "environmentSource": "environments/environment.ts",
        "environments": {
          "dev": "environments/environment.ts",
          "prod": "environments/environment.prod.ts"
        }
      }
    ],
    "e2e": {
      "protractor": {
        "config": "./protractor.conf.js"
      }
    },
    "lint": [
      {
        "project": "src/tsconfig.app.json",
        "exclude": "**/node_modules/**"
      },
      {
        "project": "src/tsconfig.spec.json",
        "exclude": "**/node_modules/**"
      },
      {
        "project": "e2e/tsconfig.e2e.json",
        "exclude": "**/node_modules/**"
      }
    ],
    "test": {
      "karma": {
        "config": "./karma.conf.js"
      }
    },
    "defaults": {
      "styleExt": "css",
      "component": {},
      "build": {
        "progress": true
      }
    }
  }
  
  //package.json
  {
    "name": "AngularTemplate",
    "version": "0.0.0",
    "license": "MIT",
    "scripts": {
      "ng": "ng",
      "start": "ng serve --extract-css",
      "build": "ng build --extract-css",
      "build:ssr": "npm run build -- --app=ssr --output-hashing=media",
      "test": "ng test",
      "lint": "ng lint",
      "e2e": "ng e2e"
    },
    "private": true,
    "dependencies": {
      "@angular-devkit/schematics": "0.0.40",
      "@angular/animations": "^5.0.0",
      "@angular/common": "^5.0.0",
      "@angular/compiler": "^5.0.0",
      "@angular/core": "^5.0.0",
      "@angular/forms": "^5.0.0",
      "@angular/http": "^5.0.0",
      "@angular/platform-browser": "^5.0.0",
      "@angular/platform-browser-dynamic": "^5.0.0",
      "@angular/platform-server": "^5.0.0",
      "@angular/router": "^5.0.0",
      "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.8",
      "@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.5",
      "D": "^1.0.0",
      "angular-basic-modal": "^4.1.0",
      "aspnet-prerendering": "^3.0.1",
      "bootstrap": "^4.0.0-beta.2",
      "core-js": "^2.4.1",
      "enhanced-resolve": "^3.3.0",
      "font-awesome": "^4.7.0",
      "jquery": "^3.2.1",
      "popper": "^1.0.1",
      "popper.js": "^1.12.9",
      "rxjs": "^5.5.2",
      "zone.js": "^0.8.14"
    },
    "devDependencies": {
      "@angular/cli": "1.6.0",
      "@angular/compiler-cli": "^5.0.0",
      "@angular/language-service": "^5.0.0",
      "@types/jasmine": "~2.5.53",
      "@types/jasminewd2": "~2.0.2",
      "@types/node": "~6.0.60",
      "codelyzer": "^4.0.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.7.0",
      "typescript": "~2.4.2"
    }
  }
  </code></pre>