Easy Fix to a Common Angular Module Error | John Papa

John Papa

Evangelist on the loose

Easy Fix to a Common Angular Module Error

...

I love running my code right after making some new changes, so I can see them light up in the browser. But I don’t love when error messages are not straight forward. At least not to me.

Recently I ran a project and was told ngLocale is not available! What? I’m not loading ngLocale, what does Angular want from me? After some digging in the console and Chrome debugger I uncovered more information about the issue.

"[$injector:nomod] Module 'ngLocale' 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.16/$injector/nomod?p0=ngLocale"    

This didn’t help much but luckily I’d seen this before and recalled that it happens when I tried to include a module dependency that did not exist. This happens due to a number of reasons such as removing a script for index.html for a module but leaving in the module dependency or even misspelling a module dependency. (Turns out my issue was the former.) So this was easy to fix once you knew that.

But the message is not very clear. Or is it? I read the message to say that ngLocale is misspelled or not loaded. I wasn’t using ngLocale so this threw me off at first. But after reading the message again it might be trying to tell me that a module (any module) was not spelled correctly or was not loaded. Ah! If that is the intent, then we can start looking at other module dependencies to resolve it.

Either way, I think this error message needs some refactoring. Hopefully this post helps you avoid or prevent this issue from being a time sink.

tags: angular
  • Md. Shohel Rana

    Hi @johnpapa7:disqus Do you know? how can i unload module dynamically using angular? Is there any angular service?

    • http://michaelcalkins.com/ Michael Calkins

      There’s probably never a good reason for doing that. I’d recommend refactoring.

  • Pingback: Have you already encountered the “Uncaught Object” exception? | Congral Discussions

  • nikivancic

    I kept running into this issue last 10 days (not sure why did I not see this long before), so I decided to probe a tad deeper and described my findings at http://www.congral.com/2014/05/29/have-you-already-encountered-the-uncaught-object-exception/

  • Robson Ramos

    I had the same problem and spend some time until find the solution because the message was not clear….

  • Charlie Martin

    I am getting this error by simply including the angular.js file. I’m not even referencing window.angular or declaring any modules yet. I’m using the latest angular 1.2.16. Any ideas?

    • aderowbotham

      the something in `ng-app=”something”` in your html must match the name of your main app module.

      • Charlie

        So my issue was quite unique, but in case anyone else has a similar problem, I’ll share. There is a bug in chrome where it truncates long console error messages, which was turning Angular’s extremely useful error messages into simply “Uncaught object”. To be able to see the actual error, I put a console.log in the minErr function in angular. However, I didn’t realize that this error about ngLocale is actually thrown (and later caught) by angular every time it initializes. So all I had to do was remove my console.log and ignore that error as its not a problem

  • David

    Thank you for posting this! It helped me get a little closer to getting my app running.

    • demisx

      David, create a plunkr showing the error you are getting and the chances of someone responding to your question will be much higher.

  • obviously

    I still don’t get it. You say it’s a simple fix, but I don’t see any actual code examples in this post that demonstrate the fix.

    I tried the following and still get the error using 1.3.0-rc0:

    var app = angular.module(“demo”, ["ngLocale"]);

    What am I missing here?

    • johnpapa7

      This particular message may not mean you are missing ngLocale. Instead, it happens when a module cannot be found. The first thing you need to do is make sure all modules dependencies are spelled right, then make sure all files are loaded.

  • Jose Marcenaro

    Thanks for taking the time to post this. You saved me – and probably others as well – many hours of debugging. Thanks again!

%d bloggers like this: