Angular 2 No provider for CompilerFactory
Asked Answered
G

1

8

I'm getting this error on my Ahead-of-Time compiled application:

Error: No provider for CompilerFactory!
    at NoProviderError.BaseError [as constructor] (http://localhost:5050/app.js:2413:26)
    at NoProviderError.AbstractProviderError [as constructor] (http://localhost:5050/app.js:2612:19)
    at new NoProviderError (http://localhost:5050/app.js:2651:19)
    at ReflectiveInjector_._throwOrNull (http://localhost:5050/app.js:4637:22)
    at ReflectiveInjector_._getByKeyDefault (http://localhost:5050/app.js:4671:28)
    at ReflectiveInjector_._getByKey (http://localhost:5050/app.js:4625:28)
    at ReflectiveInjector_.get (http://localhost:5050/app.js:4385:24)
    at PlatformRef_._bootstrapModuleWithZone (http://localhost:5050/app.js:10924:64)
    at PlatformRef_.bootstrapModule (http://localhost:5050/app.js:10910:24)
    at http://localhost:5050/app.js:64873:22

Application is built using NGC to generate the .ngfactory files, then TSC with a different main file to get the JS, then rollup w/Babel to complete the build. Following this guide fairly closely.

Here's my main.prod.ts:

import "reflect-metadata";

import { enableProdMode } from "@angular/core";
import { platformBrowser } from "@angular/platform-browser";
import { AppModuleNgFactory } from "./app.module.ngfactory";

enableProdMode();

platformBrowser().bootstrapModule(<any> AppModuleNgFactory)
Genovese answered 3/1, 2017 at 20:12 Comment(3)
Did you fix this?Consalve
Were you able to fix this? I'm running into same issue.Elinoreeliot
I was able to fix it using solution from @nrobinaubertin. Replace bootstrapModule with bootstrapModuleFactory and you're good to go. (no <any> cast is necessary anymore)Elinoreeliot
T
2
platformBrowser().bootstrapModule(<any> AppModuleNgFactory)

Should be

platformBrowser().bootstrapModuleFactory(AppModuleNgFactory)
Talich answered 6/1, 2017 at 14:31 Comment(3)
That's just a TS typecast to allow it to compile (a separate issue), but has no bearing on the runtime error.Genovese
I feel like I'm not as literate in Angular as you but the main ts file of your guide uses this syntax. If you're only doing aot (and no jit), I don't see why you would need two main files. Could you post your other main file and your package.json ?Talich
Yeah, the important part is bootstrapModuleFactory instead of bootstrapModule.Elinoreeliot

© 2022 - 2024 — McMap. All rights reserved.