I have an angular 2 app generated by ng cli.
- When I run ng build (or) ng build --prod --aot=false and serve up the page things just work fine.
- But when I try to enable aot by running ng serve --aot=true and serve up, the page breaks with multiple DI errors like belowVery hard to debug. Any idea on how to debug these issues?
EXCEPTION: No provider for Options!
error_handler.js:59 ORIGINAL STACKTRACE:
ErrorHandler.handleError @ error_handler.js:59
(anonymous) @ application_ref.js:272
webpackJsonp.679.ZoneDelegate.invoke @ zone.js:229
onInvoke @ ng_zone.js:271
webpackJsonp.679.ZoneDelegate.invoke @ zone.js:228
webpackJsonp.679.Zone.run @ zone.js:113
(anonymous) @ zone.js:509
webpackJsonp.679.ZoneDelegate.invokeTask @ zone.js:262
onInvokeTask @ ng_zone.js:262
webpackJsonp.679.ZoneDelegate.invokeTask @ zone.js:261
webpackJsonp.679.Zone.runTask @ zone.js:151
drainMicroTaskQueue @ zone.js:405
When you use the Angular AOT compiler, you can control your app compilation in two ways: By providing template compiler options in the tsconfig. json file. By specifying Angular metadata.
The Angular ahead-of-time (AOT) compiler converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase before the browser downloads and runs that code. Compiling your application during the build process provides a faster rendering in the browser.
On top of improved page load, bootstrap time is down to approx. 90 msec in AoT mode and fluctuates from ~80 msec to ~110 msec which implies a volatility of roughly 20%. Compared to the JiT compiler, that is 16 to 18 times faster.
Are you by any chance using: angular2-logger? I've had the exact same error and found out even though I don't actually use the Options I had to provide them for --aot to work.
Eg: In your AppModule have to following import:
import {Logger, Options} from "angular2-logger/core";
Then in you list of providers make sure you add Options:
providers: [
Logger,
Options // <-- this is key
]
That made the sure AOT included "Options".
Now, how did I find out? The error gives you the hint it cant find "Options". So I used the Developer Tools to look at the generated sources using the sourceMaps (I looked at main.bundle.js). There I searched for the string "Options" and the only hit gave me also the final hint:
__WEBPACK_IMPORTED_MODULE_9_angular2_logger_core__["Options"])
Now thate made me realize after looking at the docs I had to provide the Options as well.
Hope this helps. :)
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