0
votes

im struggling with a weird Issue with Backbone.Marionette an requireJS.

RquireJS is configured like https://github.com/marionettejs/backbone.marionette/wiki/Using-marionette-with-requirejs says:

require.config({

deps: ['main'],

paths : {
    backbone : '../vendor/backbone.marionette/backbone',
    underscore : '../vendor/underscore/underscore',
    jquery : '../vendor/jquery/jquery',
    marionette : '../vendor/backbone.marionette/backbone.marionette.min'
},
shim : {
    jquery : {
        exports : 'jQuery'
    },
    underscore : {
        exports : '_'
    },
    backbone : {
        deps : ['jquery', 'underscore'],
        exports : 'Backbone'
    },
    marionette : {
        deps : ['jquery', 'underscore', 'backbone'],
        exports : 'Marionette'
    }
}
});

The main.js:

require([
    'app'
],
function(App) {
    App.start();
}
);

And the app.js:

define([
    'marionette'
],
function(Marionette) {
    var app = Marionette.Application();
    return app;
}
);

But when I wanna start a Application my Console says:

Uncaught TypeError: Object #<Object> has no method '_initRegionManager' 

I did nothing special so far:

define(
[
    'marionette'
],
function(Marionette) {
    "use strict";

    var app = Marionette.Application();

    // app.on('initialize:after', function() {
    //  console.log("Initialize:After");
    // });
    return app;
}
);

And in the main.js (Startingpoint) i require the code above and wanna start it. But it fails at Marionette.Application();

When i look into the marionette.js i can clearly see underscore extending the Application with the _initRegionManager-Method. Also in the Prototype-list of the Marionette-Object i can see the method.

Any ideas what i'm missing here?

1
can you also paste your require config?Rayweb_on
Edited all js files i use currentlySpyse
I dont see anything wrong, the only line that I dont understand is this... deps: ['main'], why do you have it there, in the code sample of the tutorial is not there.Rayweb_on
ok now that I understand that line, i think the error could be the versions you are using, If you are using the AMD version of Marionette then you should not need to shim marionette.Rayweb_on
Tried it both ways. With the AMD Version, including also Backbone.wreqr and so on. Exactly the same error.Spyse

1 Answers

3
votes

Your require.config ({ … }) should be in main.js and also as Ratweb_on indicated, there should not be “deps: [‘main’]” in the require.config. You can follow this example in here, and ignore the jquerymobile stuffs. Essentially it dose the initialization in the same way as your code intended. See main.js and app.js.

Updated

In your app.js

var app = Marionette.Application();

Should be

var app = new Marionette.Application();