tbranyen / github-viewer

GitHub Viewer.
MIT License
366 stars 59 forks source link

Uncaught TypeError: Cannot read property 'View' of undefined #5

Closed jessecravens closed 12 years ago

jessecravens commented 12 years ago

I'm getting "Uncaught TypeError: Cannot read property 'View' of undefined" in Chrome after adding layoutmanager plugin to backbone boilerplate.

All scripts are loading, but Im wondering if it is the execution order.

I dont know require.js that well, but it appears that layout.manager is loading before backbone.js. I'm not sure if thats it and Im not sure how require.js is handling the execution order.

Uncaught TypeError: Cannot read property 'View' of undefined

Here is my require on main.js

require([
    "namespace",
    // Libs
    "jquery",
     "use!backbone",

    // Modules
    "modules/example", 

    // Plugins
    "plugins/backbone.layoutmanager"
],

and my config.js

// Set the require.js configuration for your application.
require.config({
         // Initialize the application with the main application file
    deps: ["main"],

    paths: {
        // JavaScript folders
        libs: "../assets/js/libs",
        plugins: "../assets/js/plugins",

        // Libraries
        jquery: "../assets/js/libs/jquery",
        underscore: "../assets/js/libs/underscore",
        backbone: "../assets/js/libs/backbone",

        // Shim Plugin
        use: "../assets/js/plugins/use",
            layoutmanager: "../assets/js/plugins/backbone.layoutmanager"
        },

    use: {
        backbone: {
            deps: ["use!underscore", "jquery"],
            attach: "Backbone"
        },

        underscore: {
            attach: "_"
        },

        layoutmanager: {
            deps: ["use!underscore", "jquery"]
        }
    }
});
tbranyen commented 12 years ago

You need to require:

use!plugins/backbone.layout manager instead On Feb 28, 2012 8:52 PM, "Jesse Cravens" < reply@reply.github.com> wrote:

I'm getting after adding layoutmanager plugin to backbone boilerplate. All scripts are rendering, but Im wondering if it the execution order.

I dont know require.js that well, but it appears that layout.manager is loading before backbone.js. I'm not sure if thats it and Im not sure how require.js is handlin the execution order.

Uncaught TypeError: Cannot read property 'View' of undefined

Here is my requires on main.js

require([ "namespace",

// Libs "jquery", "use!backbone",

// Modules "modules/example",

// Plugins "plugins/backbone.layoutmanager" ],

and config.js

// Set the require.js configuration for your application. require.config({ // Initialize the application with the main application file deps: ["main"],

paths: { // JavaScript folders libs: "../assets/js/libs", plugins: "../assets/js/plugins",

// Libraries jquery: "../assets/js/libs/jquery", underscore: "../assets/js/libs/underscore", backbone: "../assets/js/libs/backbone",

// Shim Plugin use: "../assets/js/plugins/use", layoutmanager: "../assets/js/plugins/backbone.layoutmanager"

},

use: { backbone: { deps: ["use!underscore", "jquery"], attach: "Backbone" },

underscore: { attach: "_" },

layoutmanager: { deps: ["use!underscore", "jquery"] } } });


Reply to this email directly or view it on GitHub: https://github.com/tbranyen/layoutmanager-example/issues/5

jessecravens commented 12 years ago

After checking Firefox, I get a friendlier exception 'Backbone is undefined.' So I'm thinking it is a execution order issue. Sorry to post a require.js misconfiguration here, but I think its relevant since Im using layoutmanager with backbone boilerplate.

jessecravens commented 12 years ago

yep that did it, off to read the require.js api.

I do have a question though. Looking at layoutmanager-example - In your config you declare your plugins, but I dont see that you require it.

use: {
    backbone: {
        deps: ["use!underscore", "jquery"],
        attach: "Backbone"
    },

    underscore: {
        attach: "_"
    },

    "plugins/backbone.layoutmanager": {
        deps: ["use!backbone"]
    }
}

You dont require it:

require([
    "namespace",

    // Libs
    "jquery",
    "use!backbone",

    // Modules
    "modules/repo",
    "modules/user",
    "modules/commit"
]

Yet, it still loads in the proper order in your example.

I have to require using:

require([
    ...
    // Plugins
    "use!plugins/backbone.layoutmanager"
],

and also configure my use:

use: {
    ...

    "plugins/backbone.layoutmanager": {
        deps: ["use!backbone"]
    }
}

Im not seeing the differences here? Why do I need to require, when in your example you don't?

tbranyen commented 12 years ago

Its being required in namespace.js

jessecravens commented 12 years ago

required in namespace.js

tbranyen commented 12 years ago

I think the define call there is misleading. It is most certainly required there and not defined. The definition happens within the use.js plugin.