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.

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?

  • 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.

%d bloggers like this: