Can't resolve parameter to service (?) only in non-AOT mode

207 Views Asked by At

I've seen lots of cases where AoT compilation fails for one reason or another, or generates a weird run-time error. I have the reverse problem: my app fails in non-AoT mode with the error:

Can't resolve all parameters for ConfirmRemoveService (?)

This occurs whether I not I am targeting development or production, and whether or not I am using the dev or the prod environment. For example, a pure dev build succeeds as long as I also turn on AoT explicitly:

ng serve -dev --aot

The ? in the error message above refers to the type MatDialog, from the Angular Material2 library. (This ConfirmRemoveService is a service used by components to put up a modal dialog.)

This issue may or may not be related to upgrading to the beta 11 version of that library. It may or not be related to my changing from a single import of MaterialModule directly from the library, since MaterialModule has now been removed, to my own module which imports individual Angular Material2 modules such as MatDialogModule; I then import that module where necessary. However, none of these things prevent the application from running in AoT mode; it's just in non-AoT mode that the error manifests itself.

Is anyone aware of a scenario where such a problem could occur only in a non-AoT scenario, and why?

1

There are 1 best solutions below

5
On

This problem turns out to have been due to a missing line in tsconfig.json:

"emitDecoratorMetadata": true

I think I removed this at some point in a fit of housekeeping, thinking that it was only necessary when compiling Angular-friendly libraries.

My suspicion is when running under AoT, ngc is used instead of tsc, and ngc provides this setting by default, thus accounting for the bug manifesting itself only in non-AoT mode.