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?

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

  • Tally

    This error may occur if the order of modules in your index.html contains a module usage before its declaration.

  • Guest

    I found you need to install the package i18n (nuget AngularJS.Locale for VS users) and reference that module in your controller. Only way around it afaik. Even if you are not using locales.

    module(“app”, [“ngLocale” <<== need this

    • Rachna Shukla

      Sorry posted to main stream of post. wired behavior with IE11 in native OS windows server 2012 R2, I have attached snapshot of RU IE11 version. found web application i broken only with IE11 build number 11.0.3 in native machine

  • mark.keckeis@gmail.com

    Glad to have found this discussion. You know those moments when you think that Rod Serling is going to walk into the room at any moment – or maybe the USC Marching Band is going to walk up the hall…? Haha

    I am having the same challenge. I get http 303 code for my dependencies – from what I can see – it is finding the dependencies but I cant tell from the ‘ easy to understand’ http docs whether the file is actually loading or not.

    Any tips?

  • crewman

    I got this same error with 1.4 by putting an async attribute on the script tag that loaded my main app:

    The async tag was understandably making myapp not be available in time.

    • Udaiveer Singh

      The scrips are already loaded async? are you trying to order them?

  • http://rdn-consulting.com/blog Robert Nadler

    The App ran fine but I got this error when running tests. Another easy fix. In addition to your index.html, don’t forget to add the module script to the files list in karma.conf.js.

    • Ron S

      I wish I see your reply an hour ago. :-) Thanks.

  • Rachna Shukla

    I am facing critical issue with IE11 on native LP windows server 2012 R2 on my web application using asp.net, and HTM pages with AnularJS.

    so further question is

    do i need to add module(“app”, [“ngLocale” ….to all my modules ???

  • Mhac Gallares

    I have This Error : How can I fix This , Please Help

    Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to:

    Error: [$injector:nomod] Module ‘starter’ is not available! You either misspelled the module name

  • https://cesarvegax.wordpress.com Cesar Vega

    The solution is super simple just make sure you put your dependency after the app.js main file like this in your index.html

    <script src="scripts/controllers/main.js"></script>

    &lt;script src="scripts/controllers/about.js"&gt;&lt;/script&gt;

    // New module to be reference

  • Udaiveer Singh

    I got the same error, but it was because I forgot the angular.module(“name”, [])

    you cant forget the [] or it wont inject and dependencies.

%d bloggers like this: