Cannot call method 'bind' of undefined - Backbone LayoutManager

192 views Asked by At

I don't understand what I'm doing incorrectly. I'm trying to use Backbone LayoutManager in my application and the simple code below causes the error: 'Cannot call method 'bind' of undefined'

This is my main.js file:

require.config({
    paths: {
        jquery: 'libs/jquery',
        underscore: 'libs/underscore',
        backbone: 'libs/backbone',
        layoutManager: 'libs/backbone.layoutmanager',
        knockout: 'libs/knockout',
        templates: '../templates'
    },

    shim: {

        backbone: {
            deps: ['jquery','underscore'],
            exports: 'Backbone'
        },
        layoutManager: {
            deps: ['jquery','underscore', 'backbone'],
            exports: 'LayoutManager'
        }
    }

});

require([
    'app',
    'backbone',
    'layoutManager'
], function(App, Backbone, LayoutManager) {

        // Set all Views to be managed by LayoutManager.
    Backbone.Layout.configure({ manage: true });

    App.initialize();

});

Any idea what's causing this error?

1

There are 1 answers

0
tbranyen On BEST ANSWER

Depending on the version of LayoutManager that you're using, it could be that you're shimming incorrectly. Latest LayoutManager supports AMD, so the shim is unnecessary.

As noted by @kryger's comment you received, ensure that underscore is properly shimmed. I'm willing to bet that's your problem.

shim: {
    backbone: {
        deps: ['jquery', 'underscore'],
        exports: 'Backbone'
    },

    underscore: { exports: '_' }
}

You can also check out the documentation for configuring AMD: https://github.com/tbranyen/backbone.layoutmanager/wiki/Installation#asynchronous-module-definition-amd

^^ I've updated the above to contain the line for underscore shimming as well.