nael
nael

Reputation: 1507

AngularJS Error: [$injector:unpr] Unknown provider: eProvider <- e <- $exceptionHandler <- $rootScope

I am suddenly seeing this error on our EC2 production instance. I deployed a new release and realized the error. Afterwards, I deployed the earlier version but the issue did not get resolved. The error shows up no matter whatever previously working commit I deploy.

Upvotes: 2

Views: 2361

Answers (2)

Andy Ward
Andy Ward

Reputation: 224

The error was caused by minification. There are two syntaxes for injection, implicit and explicit.

  1. Implicit injection infers what should be injected by the variable names:

    some_module.module_component(function(myService) {...

That will look for something named myService and inject it, but if the variable name is minified to something like "e", it won't be able to find any service named "e", so angular complains that there is no eProvider.

  1. Explicit injection uses strings to specify injections, and strings are never minified:

    some_module.module_component(["myService", function(myService) {...

That will look for something named myService and assign it to the myService variable, and if the variable name changes, it doesn't matter because it will still know to look for myService even if it ends up assigning it to a variable named "e".

Upvotes: 6

nael
nael

Reputation: 1507

The issue has been resolved and it needs you to pay attention to detail in source code as it is not as easy as pointing to a specific line in your code from the browser console error or how others have explained debugging through break points in the browser developer tools.

Whenever you get an error like this, you should dissect the information in the AngularJS error as follows:

Unknown provider: eProvider <- e <- $exceptionHandler <- $rootScope

  1. Unknown Provider means you have an injection issue probably caused by minified version of angularjs code you have. What minified means, is that your compiled angularjs files have renamed a service or variable that you injected into one of your angular module components (controller, service, factory, directive, decorator, etc). The rename (e.g. from $delegate to e) could cause issues in the minified version compiled. Yes not much of help to fix the issue but you should make sure you understand this.

  2. eProvider <- e has no meaning as that is the minified name that your injected object got and do not try to search for it in your code base. That won't help.

  3. $exceptionHandler: This is the biggest hint. You need to find the module or modules that have a component using this service or object. One of them is causing the issue. The one that would be causing such issue is the one that would look like this:

some_module.module_component(function(myService) {...

and to fix it, it should look like this:

some_module.module_component(["myService", function(myService) {...

It still confusing me, why I still saw the issue even when I reverted the deployed revision to a previously working revision. It seemed like the compiled JS files on the EC2 instance are not revert back.

I hope this helps.

Upvotes: 2

Related Questions