How to debug angular 2 aot errors

I have an angular 2 application created by ng cli.

- When I run ng build (or) ng build --prod --aot = false and serve the page, everything works fine.
- But when I try to enable aot by running ng serve --aot = true and submitting the request, the page breaks into several DI errors, for example below

It is very difficult to debug. Any idea on how to debug these issues?

EXCEPTION: No provider for parameters!
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

+5
source share
1 answer

Do you accidentally use: angular2 -logger ? I had exactly the same error and it turned out, although I actually do not use the parameters that I had to provide for them - it does not work.

For example: in your AppModule you need to import:

import {Logger, Options} from "angular2-logger/core"; 

Then, in the list of suppliers, make sure you add options:

 providers: [ Logger, Options // <-- this is key ] 

This led the AOT to enable Options.

Now how do I know? The error gives you a hint that cannot find the "Options". So I used Developer Tools to look at the generated sources using sourceMaps (I looked at main.bundle.js). There I searched for the line "Parameters", and the only blow gave me also the last hint:

 __WEBPACK_IMPORTED_MODULE_9_angular2_logger_core__["Options"]) 

Now it made me understand by looking at the documents that I had to provide in the settings.

Hope this helps. :)

+13
source

Source: https://habr.com/ru/post/1014690/


All Articles