Get the message when running the app in browser prod/aot mode. Below is my main-aot.ts
Uncaught NullInjectorError: StaticInjectorError(Platform: core)[CompilerFactory]: NullInjectorError: No provider for CompilerFactory!
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { platformBrowser } from '@angular/platform-browser';
//import { AppModuleNgFactory } from './app/app.module.ngfactory';
import { AppModule } from './app/app.module';
enableProdMode();
// tslint:disable-next-line:no-console
/*platformBrowser().bootstrapModuleFactory(AppModuleNgFactory).catch(err => {
console.log('CANNOT LOAD AOT MODULE')
console.dir(AppModuleNgFactory);
console.error(err)
});*/
platformBrowser().bootstrapModule(AppModule).catch(err => {
console.log('CANNOT LOAD AOT MODULE')
console.dir(AppModule);
console.error(err)
});
I was getting this error because I was not running ```ngcc`` as now required with Angular 9 when Ivy is enabled. So to fix this I added the following to my package.json scripts:
"postinstall": "ngcc"
Then ran it:
npm run postinstall
Also, the following bootstrap code was sufficient, platformBrowserDynamic is not required with AOT enabled:
platformBrowser().bootstrapModule(AppModule)
In angular 9 with ivy, there are no ngFactory files anymore, you no longer need main-aot.ts, only main.ts should be necessary
platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch(err => console.error(err));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With