Angular2 "There is no provider for t!" and unclean (in promise): Error: DI error

I created an application in Angular 2 and ran into a problem. I used the Angular CLI to build my application, I created my components and services using the Angular CLI, and I use " ng serve " to run the application locally, and everything works fine. To create an assembly for PROD, I use the command " ng build -Prod -base-href./-aot ", it creates a DIST folder and places the folder in IIS opens the application in order. When I check the code on TFS, there is an event that automatically creates the DIST folder with jenkins and pushes the assembly to my server. Now, if I look at the application for the server, it gives the following errors: " There is no provider for t! " And Error: DI error. I don't know what I'm doing wrong here.

Below are screenshots of the error

enter image description here

enter image description here


Any help is greatly appreciated.

+6
source share
3 answers

I had the same problem. I was able to solve this:

  • ng serve -aot . I was able to find out what the missing class is because it launches AOT without running minify / uglify.
  • As soon as I did this, I was able to look at the error context to find out which component was having problems.
  • Go to the component in question and start deleting links in the constructor (where dependency resolution occurs.

In my case, I had a problem using the Logger class in the angular2 -logger / core module. As soon as I removed the link from the compiler of the constructor and the reader, it worked like a charm. Then I tested with ng serve -prod to confirm that this was also fixed.

One thing that I discovered was that I had to explicitly kill the Angular CLI and rebuild. For some reason, when I changed one line and saved it, she said that it was recompiled and still broken. Only when I killed him and ran the team again did I realize that this was really fixed.

+9
source

I had the same problem and the reason turned out to be a fad in the angular2 -logger library. This answer solved the problem for me

0
source

fixed! in my case this happened because the NotificationService for angular2 -notifications

the solution simply removes the NotificationService from the array of providers inside the application module .

but this must be confirmed earlier by angular in AOT mode.

Thanks!

0
source

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


All Articles