1

I'm having an issue creating an AngularJS module inside a RequireJS define method.

When I make reference to the ui-router module that I need, Angular tells me:

Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:nomod] Module 'myApp' 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 only happens if I define uiRouter in the requireJS dependency list.

Here's my code:

require.config({
    paths : {
        'angular' : "/script/lib/angular",
        'uiRouter' :"/script/lib/angular-ui-router",

    },
    shim : {
        'angular': {
            exports : 'angular'
        },
        'uiRouter' : {
            deps : ['angular']
        }
    }

});

define(['angular', 'uiRouter'], function (angular) {
    var module = angular.module('myApp', []);
});

If I take uiRouter out of the define dependency array, everything works as expected. What am I doing wrong?

7
  • what is your requirejs version? Commented Oct 6, 2014 at 14:15
  • Angular: v1.3.0-rc.4 Commented Oct 6, 2014 at 14:15
  • I edited my asnwer also where is your return statement? Commented Oct 6, 2014 at 14:19
  • Thanks @Blackunknown but creating the require module as a named module doesn't help. There's no return statement, there doesn't need to be one. Commented Oct 6, 2014 at 14:23
  • Sorry @KhanhTO, you asked about the requireJS version which is: 2.1.15 Commented Oct 6, 2014 at 14:34

1 Answer 1

0

You need to add the ui.router to your module.

define(['angular', 'uiRouter'], function (angular) {
    var module = angular.module('myApp', ['ui.router']);
});

EDIT: I added the following:

define('myApp', ['angular', 'uiRouter'], function (angular) {
    var module = angular.module('myApp', ['ui.router']);
});
Sign up to request clarification or add additional context in comments.

1 Comment

I was just adding the edit saying although it might not fix your issue. :P Lets see what else there is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.