Beartums
Beartums

Reputation: 1350

Breeze with durandal causing 'module not loaded undefined is not a function' error

Loading my payments module, i get the 'Failed to load routed module (payments). Undefined is not a function' error. I have tried everything, even rolling it back to some commits that happened a week ago, and keep getting the same error. After a lot of troubleshooting, I traced it back to my dataservice. I found that when I remove all references to 'breeze' in my dataservice, it loads as expected (though, of course, doesn't work). If I add 'breeze' back into the 'define' dependency array, I get the undefined is not a function error.

I haven't changed the require. config, but I have pasted it below along with the define statement for my dataservice.

require.config({
    paths: {
        'ko': '../Scripts/knockout-3.1.0',
        'breeze': '../Scripts/breeze.debug',
        'jquery': '../Scripts/jquery-2.1.1',
        'jquery-ui': '../Scripts/jquery-ui-1.11.2',
        'bootstrap': '../Scripts/bootstrap.min',
        'text': '../Scripts/text',
        'require': '../Scripts/require',

        // JS Object Serializer/deserializer.  Handled cyclic objects, efficient stringifying.
        'JSOG': '../Scripts/JSOG',
        'domReady': '../Scripts/domReady',
        'Q': '../Scripts/q',

        // Notifications
        'toastr': '../Scripts/toastr',

        //Durandal
        'durandal': '../Scripts/durandal',
        'plugins': '../Scripts/durandal/plugins',
        'transitions': '../Scripts/durandal/transitions',

        // Lazy-developer date formatting
        'moment': '../Scripts/moment.min'
    },
    map: {
        '*': { 'knockout': 'ko' } // Necessary for Durandal, expects Knockout to be 'knockout', not 'ko'
        //                           Breeze expects 'ko'??
    },
    shim: {
        'bootstrap': {
            deps: ['jquery'], // don't load the bootstrap.js until jquery is loaded
            exports: 'bootstrap'
        },
        'JSOG': {
            exports: 'JSOG'
        }
    }

and my define statement for the dataservice:

define(['ko', 'breeze', 'logger', 'Q', 'constants', 'JSOG'], function (ko,breeze,logger,Q,c,JSOG) {

Please help. I'm sure it's something simple, but I've been tearing my hair out.

EDIT: Per Jeremy's request, here is the stack trace:

TypeError: undefined is not a function
at proto.initialize     (http://localhost:62418/Scripts/breeze.debug.js:15785:26)
at initializeAdapterInstanceCore (http://localhost:62418/Scripts/breeze.debug.js:1870:14)
at Object.__config.getAdapterInstance (http://localhost:62418/Scripts/breeze.debug.js:1818:14)
at breeze.AbstractDataServiceAdapter.proto.initialize (http://localhost:62418/Scripts/breeze.debug.js:15437:30)
at initializeAdapterInstanceCore (http://localhost:62418/Scripts/breeze.debug.js:1870:14)
at __config.initializeAdapterInstance (http://localhost:62418/Scripts/breeze.debug.js:1791:12)↵    at __objectMap (http://localhost:62418/Scripts/breeze.debug.js:56:27)
at Object.__config.initializeAdapterInstances (http://localhost:62418/Scripts/breeze.debug.js:1765:12)
at http://localhost:62418/Scripts/breeze.debug.js:17358:15
at def (http://localhost:62418/Scripts/breeze.debug.js:10:34)"

The error seems to happen even if i refactor and get rid of Durandal and Require js. Even though Jquery is loaded (along with KO and Q), I get an error at var $injector = ng.injector(['ng']); apparently it is trying to load the angular ajax call even though angular is not defined.

Upvotes: 0

Views: 242

Answers (1)

Beartums
Beartums

Reputation: 1350

Looks like I figured it out. I do some development work in AngularJS as well and many moons ago I installed the AngularJS Batarang extension for Chrome. I haven't used it for a while, so I forgot about it. I disabled it, closed and reopened the browser and -- Walla! -- everything is working again.

I'm guessing breeze somehow detected angular was loaded in the extension and then tried to load the $http, which it couldn't access, and everything fell apart. I don't know why it started happening just yesterday (maybe it had been disabled and somehow got accidentally enabled again) but that's the problem. I can make the error happen or go away at will.

Upvotes: 2

Related Questions