RequireJS – is jQuery case sensitive?

Yes, jQuery defines itself as ‘jquery’, all lowercase. That’s normal.

If you open the source to jQuery you’ll find:

// Register as a named AMD module, since jQuery can be concatenated with other
// files that may use define, but not via a proper concatenation script that
// understands anonymous AMD modules. A named AMD is safest and most robust
// way to register. Lowercase jquery is used because AMD module names are
// derived from file names, and jQuery is normally delivered in a lowercase
// file name. Do this after creating the global so that if an AMD module wants
// to call noConflict to hide this version of jQuery, it will work.
if ( typeof define === "function" && define.amd ) {
    define( "jquery", [], function () { return jQuery; } );
}

So you have to refer to it as "jquery" everywhere in RequireJS calls. The issue here is that the define that jQuery uses is a “named define which is something we normally do not use when creating modules. The RequireJS optimizer adds these names for us when we run it.

At any rate, when a “named define” is used the module name is set to the name given to define rather than by file names (as is otherwise the case when we don’t use a named define).

It is possible to rename "jquery" to "jQuery", like this:

require.config({
  baseUrl: "./js",
  paths: {
      "jquery": "jquery-1.10.2"
  }
});

define("jQuery", ["jquery"], function ($) {
   return $;
});

require(["jQuery"], function ($) {
   console.log($);
   console.log($("body")[0]);
});

I’m making use of the version of define that takes a name as the first parameter. Full example here.

Leave a Comment