Avoid the minified AngularJS library in development

I’m still learning AngularJS, which means I can get stuff done but I’m dangerous. A few days ago I ran into a problem that drove me crazy. I was trying to use ngCordova in an existing AngularJS application and kept running into a problem injecting the library into my controller. The error message was less than helpful. Heck, it was useless. Let’s look at an example.

I grabbed a copy of the AngularJS seed project (https://github.com/angular/angular-seed) to create a quick simple AngularjS application. (Before this I tried yeoman but after thirty minutes of fighting it and it hanging I decided to give up.) I then set the application to use the minified version of the AngularJS library. That’s the key. Then I opened up one of the JavaScript files and modified the dependencies to include something bad (literally):

Yeah, have fun with that. In case you don’t feel like scrolling over the entire thing, I’ll save you the trouble and say it basically is gibberish to anyone who doesn’t have a computer as a brain. So I struggled with this for a while until a random StackOverflow post (sorry, forgot to bookmark it!) mentioned that using the minified version of the AngularJS library actually changes how errors are reported. That seemed…. odd. But for the heck of it I switched back. The result is incredibly improved:

Error: [$injector:modulerr] Failed to instantiate module myApp due to:
[$injector:modulerr] Failed to instantiate module myApp.view1 due to:
[$injector:modulerr] Failed to instantiate module somethingbad due to:
[$injector:nomod] Module 'somethingbad' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.2.28/$injector/nomod?p0=somethingbad
minErr/<@http://localhost:8000/app/bower_components/angular/angular.js:78:12
module/<@http://localhost:8000/app/bower_components/angular/angular.js:1677:1
ensure@http://localhost:8000/app/bower_components/angular/angular.js:1601:38
module@http://localhost:8000/app/bower_components/angular/angular.js:1675:1
loadModules/<@http://localhost:8000/app/bower_components/angular/angular.js:3877:22
forEach@http://localhost:8000/app/bower_components/angular/angular.js:325:9
loadModules@http://localhost:8000/app/bower_co angular.js:78

In my particular case, it was a bug in ngCordova’s custom build code where the top level module couldn’t load a lower level module. Switching to the non-minified version fleshed this out immediately.

I have to be honest - I can’t imagine why error reporting is something you would get rid of in minification. I guess the hope is that you don’t have errors like this in production but I know I never would have guessed this. I typically use the minified version of frameworks like this as I don’t expect to need to inspect/debug the library itself. Does anyone know if other frameworks (Ember, etc) also do this?

About Raymond Camden

Raymond is a developer advocate looking for his next gig. He focuses on JavaScript, serverless and enterprise cat demos.
If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.