3

I have successfully created .ngfactory files using ngc compiler and have also updated my main.ts with "platformBrowser().bootstrapModuleFactory(AppModuleNgFactory)".

app.routes.ts

const appRoutes: Routes = [
    { path: '', loadChildren: 'app/starter/starter.module#StarterModule' },
    ...
    ...
    ...
];

export const appRoutingProviders: any[] = [

];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

Now, when i serve my app using "ng build -prod && ng serve -prod", it hosts successfully. However, when i open it on my browser my console shows me this error "EXCEPTION: Uncaught (in promise): Error: Cannot find module 'app/starter/starter.module.ngfactory'."

And when i check my directory the file "does" exist yet its unable to find it. Has anyone face this problem? If yes, then how to tackle it? Thanks.

I'm using Angular-cli beta 14.

Sumit patel
  • 3,807
  • 9
  • 34
  • 61
  • 1
    Having the same problem with custom build, looks like AoT compiler doesn't precompile lazy modules... – tomastrajan Sep 22 '16 at 23:15
  • 1
    @tomastrajan If you happen to find any solution please make sure to share the solution. I've been stuck on this problem for too long and can't find any work around to it. – Manul Aggarwal Sep 23 '16 at 08:35

1 Answers1

2

the aot output only takes the files you add in your files-array in the tsconfig-aot.json. So be sure to add all your modules there including those who are lazy loaded. Because they are not included anymore through the app itself exept for the "loadChildren" in the router.

 "files": [
"app/app.module.ts",
"app/starter/starter.module.ts",
"app/main.ts"  ],

After that in the AoT Folder should be all modules compiled. After that you can take the output in the "aot" folder (or which folder you build the compilation to) and do treeshaking etc.

An example of this, but without the angular-cli, using webpack can be found here:

https://github.com/FabianGosebrink/ASPNET-ASPNETCore-AngularJS-Angular/tree/master/Angular-Client-Webpack

FabianGosebrink
  • 305
  • 2
  • 12