Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Unknown provider in minified angular javascript

I'm having a hard time trying to pinpoint which, of the very many, methods I have in my angular app that would be causing the error:

Uncaught Error: [$injector:unpr] Unknown provider: nProvider <- n

This only happens once the javascript has been bundled & minified by ASP.Net.

I have ensured that all the controllers, and any other DI, is using the minification-safe method, I.E My controllers/service etc are using the method:

appControllers.controller('myCtrl', ['$scope', function($scope){         //...... }]); 

I've gone through every JS file in our app - there are a lot... and can't find anything that violates this way of injecting dependencies - though there must be one somewhere...

Is there a better way to pinpoint which method could be causing this error?

Thanks

like image 398
Darren Wainwright Avatar asked May 05 '14 19:05

Darren Wainwright


1 Answers

For anyone else struggling with this problem, I found an easier solution. If you pull open your developer console (on chrome) and add a breakpoint where angular throws the error:

angular throwing an error

Then, on the stack trace on the right, click on the first "invoke" you see. This will take you to the invoke function, where the first parameter is the function angular is trying to inject:

I was able to inspect the function

I then did a search through my code for a function that looked like that one (in this case grep "\.onload" -R public), and found 8 places to check.

I hope this helps!

like image 198
yourdeveloperfriend Avatar answered Oct 05 '22 00:10

yourdeveloperfriend