Reputation: 815
I am currently attempting to introduce AOT compilation to my Angular2 project.
After following all of the steps set out in https://angular.io/guide/aot-compiler, I received the error specify either statically analyzable bootstrap code or pass in an entrymodule to the plugins options
after running the command ng build --aot
.
import { enableProdMode } from '@angular/core';
import { platformBrowser } from '@angular/platform-browser';
import { AppModuleNgFactory } from '../aot/src/app/app.module.ngfactory';
if (environment.production) {
enableProdMode();
};
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
Upvotes: 1
Views: 1152
Reputation: 815
Apparently with @angular/cli none of the steps set out in https://angular.io/guide/aot-compiler are needed and the main.ts
file can stay the same. This is because AOT compilation is now built into the angular cli and runs as default on ng build --prod
.
After reverting my main.ts
file back to:
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/modules/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule);
I received a new error Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
after reading the issue https://github.com/angular/angular/issues/18380 the issue was solved by updating my @angular/cli version to 1.2.6. Everything is now working fine.
Upvotes: 1