Skip to content Skip to sidebar Skip to footer

Cannot Read Property 'view' Of Undefined

This is my first time to use require.js with backbone, and I'm struggling to find the problem with my view: Cannot read property 'View' of undefined // search.js:8 My directory st

Solution 1:

Backbone and Underscore are not AMD-compliant. By default, they don't provide an interface compatible with RequireJS.

In last versions, RequireJS provide a useful way to solve the problem:

Your main.js:

require.config({
  shim: {
    underscore: {
      exports: '_'
    },
    backbone: {
      deps: ['underscore', 'jquery'],
      exports: 'Backbone'
    }
  },
  paths: {
    jquery: 'lib/jquery-min',
    underscore: 'lib/underscore-min',
    backbone: 'lib/backbone-min',
    templates: '../templates'
  }

});

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

Solution 2:

To extend BAK's answer, you'll need to provide a baseUrl too:

require.config({
  baseUrl: 'js',
...
});

Post a Comment for "Cannot Read Property 'view' Of Undefined"