0

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.

Beartums
  • 1,340
  • 1
  • 10
  • 15
  • what's the call stack for the "Undefined is not a function" error? – Jeremy Danyow Dec 10 '14 at 13:42
  • @Jeremy, to the rescue again. I don't have the cal stack at the moment -- I have refactored the application to get rid of Durandal and RequireJS but I'm still getting the error. Looks like breeze is trying to load the angular injector (line 15785 ` var $injector = ng.injector(['ng'])`) which doesn't exist. If I travel back up through the call stack, I find the line 15437 (`ajaxImpl = breeze.config.getAdapterInstance("ajax");`) seems to be the actual cause of the error -- it never gets to the next line of the code, but rather but somewhere gets shunted off to throw the error mentioned. – Beartums Dec 10 '14 at 15:09
  • k- my knee jerk reaction here is to drop angular instead. Angular 2.0 is a complete rewrite so you'll quite a bit of refactoring to do if u want to keep your app current. Plus Durandal is AWESOME for SPA apps. Rob Eisenberg is the man. http://eisenbergeffect.bluespire.com/leaving-angular/ – Jeremy Danyow Dec 10 '14 at 15:26
  • I think you're telling me that I shouldn't be using angular and should be using Durandal instead, but that's the thing -- I'm not using angular. I think for some reason breeze is not seeing jquery and is trying to work with angular instead. I have no idea why that is happening. – Beartums Dec 10 '14 at 15:32
  • 1
    @Jeremy, I figured it out. A waste of a day, but I'm glad to have it behind me. THanks for your help, and thanks for the link -- I didn't know Eisenberg and Angular had parted ways. I had been worried about the Durandal route (because of the projected angular convergence), but now it will probably make more sense. – Beartums Dec 10 '14 at 16:03

1 Answers1

2

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.

Beartums
  • 1,340
  • 1
  • 10
  • 15
  • 1
    They released an update of Batarang in the last day or two and it's been havoc for everyone ever since. I would NOT be surprised to learn that Batarang introduced a copy of Angular, Breeze saw it, and got confused. We have not tried to test Breeze with both KO and Ng loaded as that is an unlikely scenario (to put it politely). – Ward Dec 11 '14 at 06:03