Module is not available, misspelled or forgot to load (but I didn't)
Asked Answered
W

9

64

I am fairly new to angular and using it with JSON api files. TO test, I am trying to use the free github api (my names for functions are for a different json api that i will be working with later). I just wanted to see if my functions were working with console.log(), but i receive this error in the console.

Uncaught Error: [$injector:modulerr] Failed to instantiate module MesaViewer due to: Error: [$injector:nomod] Module 'MesaViewer' 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.

I have spelled MesaViewer the exact same in both, and dependencies are seen in the second line!

var app = angular.module("MesaViewer");
var MainController = function($scope, $location, $http, $routeParams) {

What did I do wrong? Here is my plunk: http://plnkr.co/edit/sZPaFbzbOB6AmVCLL1vq

Wendt answered 13/7, 2015 at 22:55 Comment(1)
as a part of the syntax, [] is mandatory. It is used to add dependencies in to your app, e.g., other modules. like ['yourModuleName', 'anotherModule']. You still got to include the blank array, [] even if you have no dependencies on other modules.Voronezh
H
100

It should be

var app = angular.module("MesaViewer", []);

This is the syntax you need to define a module and you need the array to show it has no dependencies.

You use the

angular.module("MesaViewer");

syntax when you are referencing a module you've already defined.

Holierthanthou answered 13/7, 2015 at 23:1 Comment(1)
And make sure that if you have multiple js files referenced in your HTML, that the one where the module is defined is loaded first, or you will still get a "nomod" error, even if you have declared it.Walsingham
H
15

You are improperly declaring your main module, it requires a second dependencies array argument when creating a module, otherwise it is a reference to an existing module

Change:

var app = angular.module("MesaViewer");

To:

var app = angular.module("MesaViewer",[]);

Working Version

Hypercorrect answered 13/7, 2015 at 23:3 Comment(0)
A
11

I had the same error and fixed it. It turned out to be a silly reason.

This was the culprit: <script src="app.js"/>

Fix: <script src="app.js"></script>

Make sure your script tag is ended properly!

Angelaangele answered 18/7, 2017 at 16:30 Comment(1)
Possibly even sillier for me! I had accidentally typed the src as "/js/app.js", when what I really wanted was "js/app.js" without the initial slash. That meant it worked in one development environment but not another!Choking
R
7

I found this question when I got the same error for a different reason.

My issue was that my Gulp hadn't picked up on the fact that I had declared a new module and I needed to manually re-run Gulp.

Radu answered 25/1, 2017 at 19:24 Comment(0)
S
5

I got this error when my service declaration was inside a non-invoked function (IIFE). The last line below did NOT have the extra () to run and define the service.

(function() {
    "use strict";

    angular.module("reviewService", [])
        .service("reviewService", reviewService);

    function reviewService($http, $q, $log) {
        //
    }
}());
Sacramentalist answered 3/3, 2020 at 23:11 Comment(2)
someone give this guy a medal. Thanks Todd.Sequential
Thanks, I'm new to AngularJS but was sure I had declared the module correctly, it was driving me nuts. This was the cure!Fang
A
4

I have the same problem, but I resolved adding jquery.min.js before angular.min.js.

Affiliate answered 28/5, 2017 at 21:27 Comment(0)
B
4

make sure that you insert your module and controller in your index.html first. then use this code in your module var app = angular.module("MesaViewer", []);

Burchell answered 6/9, 2018 at 9:58 Comment(0)
P
2

Using AngularJS 1.6.9+

There is one more incident, it also happen when you declare variable name different of module name.

var indexPageApp = angular.module('indexApp', []);

to get rid of this error,

Error: [$injector:nomod] Module 'indexPageApp' 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.

change the module name similar to var declared name or vice versa -

var indexPageApp = angular.module('indexPageApp', []);
Penicillate answered 30/6, 2018 at 14:37 Comment(0)
H
1

I had the same error but i resolved it, it was a syntax error in the AngularJS provider

Hussey answered 3/7, 2017 at 6:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.