Finding the cause of “Unknown provider” errors
Posted by ark, ,
My boss IM'd me Sunday morning asking what broke in our Angular app. The only error message on the console was the dreaded.

Error: [$injector:unpr] Unknown provider: eProvider <- e
It all worked fine in our dev environment, it was only the minified version that had the problem. The cause of this is well known, see A Note on Minification on the AngularJS website. So somewhere I have something like `.run(function(e){...})` in my minified code and I just have to find it. Unluckily for me, I had just been through a huge code organizing binge and pretty much touched every source file and was particularly messing with the layout of our injectable blocks.

Looking at the 57 line 1.4Meg compiled javascript file I found 4017 functions that take 'e' as a parameter ` egrep -o 'function\([^)]*\be' `. That's just under half of all the functions in the file.

To find the problem I modified the uglifyjs JavaScript compiler to create a globally unique id every time an id was created.

./bin/uglifyjs --unique_ids original.min.js >new.min.js

I ran the minified code through uglify and then served up this new code and sure enough I got an Unknown provider: e453Provider <- e453
Trolling through the minified code it was easy to find the block where e453 was and with a bit of poking around I could find where the problem was. Root cause: someone checked in hotkeys.js from the src/ directory and not the build/ directory...

I have a pull request pending to add my flag to uglifyjs but until that happens (or if it doesn't) you can download it here: https://github.com/arkarkark/UglifyJS

This was my first time playing with some node.js code.

I also added my answer to this Stack Overflow question (and finally started building some reputation there): Finding the cause of “Unknown provider” errors.

Comments

Posted Tuesday 5 August 2014 Share