I am trying to debug a missing provider in a large-ish AngularJS project. The error is a missing 'dProvider'. It is only occurring on a version of the code that is minified, which makes sense, because we have no 'd' controllers, factories, or services. I am having trouble finding what is causing this, and searching through the minified code for things like function(a,b,c,d)
hasn't yielded anything yet. Is there any way to force only explicit dependency injection in Angular? It seems like if I could force this I could catch the problem in the dev environment.
Asked
Active
Viewed 1,079 times
3

xdhmoore
- 8,935
- 11
- 47
- 90
-
1try generating a source map file during your minification process - that way you should be able to determine the name of the missing provider [here is a arcticle on sourcemaps](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) – Mark-Sullivan Feb 19 '14 at 21:10
-
This could happen if you forgot to min-safe an injection. If you don't have a 'd' service it sounds like your parameters got mangled. – Nick Feb 19 '14 at 21:12
-
I hadn't thought of source maps. That's a good idea, but according to [this](http://stackoverflow.com/questions/19719780/source-maps-with-grunt), source map generation with grunt is probably beyond what I'm able to do for the moment. I understand why i could get an error like this, I'm just having trouble finding it. I'm also not confident a source map would help, because the stack trace only lists functions within angular.js, not my minified code. – xdhmoore Feb 19 '14 at 21:30
3 Answers
7
Yippee! Since Angular 1.3.1 you can turn off implicit dependency injection!
From code, using strictDi
config property:
angular.bootstrap(document, ['myApp'], {
strictDi: true
});
Or from template, using ng-strict-di
directive:
<html ng-app="myApp" ng-strict-di>

dizel3d
- 3,619
- 1
- 22
- 35
0
Wow that sucks.
It's probably a controller/service defined like this
app.controller('myCtrl', function($scope){
...
})
instead of the safer
app.controller('myCtrl', ['$scope', function($scope){
...
}])
I don't have a fool-proof answer but maybe you can search for ', function( and if you get lucky you'll find the culprit. If something like that doesn't work, source maps are probably the way to go.

NicolasMoise
- 7,261
- 10
- 44
- 65
-
Thanks, yeah, that's what I've been looking for. that or a different number of function parameters than defined dependencies... – xdhmoore Feb 19 '14 at 21:32
-
1You could also beautify your minified code (with jsbeautifier.org/ for example) and that might help you identify the line that causes the problem. Although, if I remember correctly, that error doesn't give a line in your own code :( – NicolasMoise Feb 19 '14 at 21:50
-
Yeah, that's the main problem. I could get from a minified version of my own code to the solution. But it's only listing angular.js stuff. – xdhmoore Feb 19 '14 at 21:59
0
I ended up selectively commenting out portions of my html until I determined where the issue was occurring. Turns out it was an angular-ui-bootstrap issue.

xdhmoore
- 8,935
- 11
- 47
- 90