ngcli 6.1.3 ERROR in ./src/main.ts - Can't resolve './app/app.module.ngfactory'

710 Views Asked by At

I am using angular/cli 6.1.3 and am getting an error below when trying to compile using enableIvy: true in tsconfig.app.json:

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './app/app.module.ngfactory' in 'xxxxPath'

Build command:

ng build --prod --source-map=false --base-href='/'  --extract-css=true --delete-output-path=true --aot --build-optimizer=true

The version details of angular/cli

Angular CLI: 6.1.3
Node: 10.7.0
OS: linux x64
Angular: 6.1.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.7.3
@angular-devkit/build-angular     0.7.3
@angular-devkit/build-optimizer   0.7.3
@angular-devkit/build-webpack     0.7.3
@angular-devkit/core              0.7.3
@angular-devkit/schematics        0.7.3
@angular/cli                      6.1.3
@ngtools/webpack                  6.1.3
@schematics/angular               0.7.3
@schematics/update                0.7.3
rxjs                              6.2.2
typescript                        2.7.2
webpack                           4.9.2
1

There are 1 best solutions below

1
On

This worked for me:

Remove BrowserModule from your app.module.ts file, Both from the imports section of the ngModule declaratrion and the actual ES5 import at the top of the file

And modify the bootstrapping in main.ts:

import { enableProdMode, ɵrenderComponent } from '@angular/core';
import { environment } from './environments/environment';
import { AppComponent } from './app/routes/app/app.component';

if (environment.production) {
  enableProdMode();
}


ɵrenderComponent(<any>AppComponent);

Main bundle went from 1.4mB to 636kB, can't wait.