Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs debugging of [$injector:unpr] Unknown provider: e?

Tags:

angularjs

How can I debug Angular's error:

Uncaught Error: [$injector:modulerr] Failed to instantiate module zvApp due to:
Error: [$injector:unpr] Unknown provider: e
http://errors.angularjs.org/1.4.3/$injector/unpr?p0=e
    at http://app.dev/build/js/vendor-53eec796.js:3:19384

There is some provider unknown, but which one? I can't find an easy way how to debug this. Tried it all.. Think it's a bug in a 3rd party package, but can't be sure without debugging.

like image 590
user1867254 Avatar asked Sep 08 '15 21:09

user1867254


1 Answers

Most possibly your issue is with lack of explicit dependency annotation (unless ng-annotate is used with minification), using array syntax (.service('myService', ['$http', function($http){...) or $inject static property (MyService.$inject=['$q']) on the constructor. It is very hard to find it late in the game or in the minified code. So general practice would be to use ng-strict-di with ng-app directive and while your development or running application with non minified code it will throw more informative error in the places where you lack explicit dependency annotation.

Example:-

If using ng-app then,

<html ng-app="myApp" ng-strict-di>

If manually bootstrapping, then specify it as option.

angular.bootstrap(document, ['myApp'], {
  strictDi: true
});

By turning on strict-di angular injector will specifically check for explicit annotation before instantiating and lack of which will break the application with error, this more often helps prevent these issue or catch them early in the game. Generally turning on strict-di option is helpful (and no need to remove it for production btw) in catching lack of dependency injection almost every definition including run, config and even the resolve functions (used with routers, modals etc).

like image 184
PSL Avatar answered Sep 28 '22 03:09

PSL