Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8132973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:28:31+00:00 2026-06-06T09:28:31+00:00

I am trying to modularize my Backbone app through Requirejs, but I cannot seem

  • 0

I am trying to modularize my Backbone app through Requirejs, but I cannot seem to get Requirejs to include Backbone. Here is my main.js that gets included from the index page:

require.config({
    baseUrl: '/static/js/',
    paths: {
        jquery: 'libs/jquery/jquery-min',
        underscore: 'libs/underscore/underscore-min',
        backbone: 'libs/backbone/backbone-min',
        text: 'libs/require/text',
    },
});

require(['/static/js/views/app.js'], function(AppView) {
    var appView = new AppView;
});

Here is my app.js that gets included from the above file:

define([
    'jquery',
    'underscore',
    'backbone',
], function($, _, Backbone) {
  console.log($);
  console.log(_);
  console.log("inside of the app js file");
    var AppView = Backbone.View.extend({

        initialize: function() {
            console.log("inside of appview initialize");
        },

    });
});

The following information gets printed out in my Google Chrome console:

function (a,b){return new e.fn.init(a,b,h)}
app.js:7undefined
app.js:8inside of the app js file
app.js:9Uncaught TypeError: Cannot read property 'View' of undefined

The definition for $ works, but the definitions for _ and Backbone do not work. They come up as undefined. Any idea why this is happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:28:33+00:00Added an answer on June 6, 2026 at 9:28 am

    I recommend you use the version of requireJS that has jQuery bundled. It will save you much setup pain. You can read the details here: http://requirejs.org/docs/jquery.html and download the files here: https://github.com/jrburke/require-jquery

    In their own words:

    With RequireJS, scripts can load in a different order than the order they are specified. This can cause problems for jQuery plugins that assume jQuery is already loaded. Using the combined RequireJS + jQUery file makes sure jQuery is in the page before any jQuery plugins load.

    This should take care of loading jQuery properly with requireJS:

    <script data-main="js/main" src="js/require-jquery.js"></script>
    

    Main.js

    A couple of notes here:

    • No need to re-define the path to jquery since that’s already taken care of
    • You still have to indicate jquery as a required module
    • (I had to update the paths to have them work in my system)

    Code:

    require.config({
        baseUrl: 'js/',
        paths: {
            underscore: 'libs/underscore-min',
            backbone: 'libs/backbone-min',
        },
    });
    
    require(['jquery', 'app'], function($, AppView) {
        console.log("done w/ requires");
        console.log($)
        console.log(AppView)
        var appView = new AppView;
    });
    

    app.js

    A couple notes:

    • You can only retrieve the JS files after loading them in the callback if they have been defined as modules. So function($, _, Backbone) will fail for you.
    • You must return your object so that it can be used in the main.js callback (return AppView)

    Code:

    define(
        [
        'jquery',
        'underscore',
        'backbone',
        ],
        function() {
            console.log($);
            console.log(_);
            console.log(Backbone);
            console.log("inside of the app js file");
            return AppView = Backbone.View.extend({
                initialize: function() {
                console.log("inside of appview initialize");
            },
        });
    });
    

    Console

    With that code in place, this is the console output:

    function ( selector, context ) {
        // The jQuery object is actually just the init constructor 'enhanced'
        return new jQuery.fn.init( selector, context, rootjQuery );
        } [app.js:8]
    
    function (a){return new m(a)} [app.js:9]
    
    Object [app.js:10]
    
    inside of the app js file [app.js:11]
    
    done w/ requires main.js:21
    
    function ( selector, context ) {
        // The jQuery object is actually just the init constructor 'enhanced'
        return new jQuery.fn.init( selector, context, rootjQuery );
    } [main.js:22]
    
    function (){a.apply(this,arguments)} [main.js:23]
    
    inside of appview initialize [app.js:15]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm working on a backbone app, and trying to modularize things as much
I have a classic ASP application that I've been constantly trying to modularize. Currently,
Trying to find some information on this but am unable to get any results
I was trying to learn prism, but I am unable to get a very
trying to get a regex that will match a url e.g. 'http://www.test.com' and then
trying to get a project working on my debian vm but foreman refuses to
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to copy the msdn refernce here doesn't work and gives an error I
Trying to get a wildcard search to pick up on any text in org_name
Trying to load a page fragment, or at least jump to a div but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.