Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 "No provider for t!" and Uncaught (in promise): Error: DI Error

I've build a app in Angular 2, and have encountered a issue. I have used angular CLI to create my application, I have created my components and services using Angular CLI and I use "ng serve" to run the application locally and everything works fine. In order to create a build for PROD I'm using the command "ng build --Prod --base-href ./ --aot", it creates a DIST folder and hosting the folder in IIS opens the application fine. When I check in the code to TFS there is a event which automatically creates DIST folder using jenkins and pushes the build to my server. Now if I browse the application for server it throws the following errors "No provider for t!" and Error: DI Error. I don't know what I'm doing wrong here.

Below are the screenshots of the error

enter image description here

enter image description here


Any help is much appreciated.

like image 414
Prasanna J Avatar asked Feb 03 '17 20:02

Prasanna J


1 Answers

I was having the same problem. I was able to solve it by:

  1. running ng serve -aot. I was able to find out what the missing class was as this is running AOT without running minify/uglify.
  2. Once I did that I was able to look through the error context to figure out which component was having issues.
  3. Go to the component in question and start removing references in the constructor (where the dependency resolution happens.

In my case, I was having a problem using the Logger class in the angular2-logger/core module. Once I removed the reference from the constructor and reran compilation, it worked like a charm. I then tested with ng serve -prod to confirm that was also fixed.

One thing I found was that I had to explicitly kill Angular CLI and rebuild. For some reason, when I modified one line and saved, it said it recompiled and was still broken. Only when I killed it and ran the command again did I figure out it was really fixed.

like image 59
Brian Bauman Avatar answered Oct 26 '22 13:10

Brian Bauman