fa. fa. - 14 days ago 5
jQuery Question

Uncaught Error: Bootstrap's JavaScript requires jQuery with requirejs

I am getting this error that says jQuery is not defined.

bootstrap.js:8 Uncaught Error: Bootstrap's JavaScript requires jQuerybootstrap.js:8 (anonymous function)

Bootstrap v3.3.0

jQuery JavaScript Library v2.1.3

requirejs

require.config({
shim: {
'backbone': {
deps: ['underscore', 'jquery']
},
'backbone-validation': {
deps: ['backbone', 'jquery']
},
'jquerymx': {
deps: ['jquery']
},
'bootstrap': {
deps: ['jquery']
}
},
paths: {
'jquery': '/public/js/lib/jquery-2.1.3',
'jquerymx': '/public/js/lib/jquerymx-3.2.custom',
'bootstrap': '/public/js/lib/bootstrap',
'handlebars': '/public/js/lib/handlebars-v2.0.0',
'underscore': '/public/js/lib/underscore',
'backbone': '/public/js/lib/backbone',
'backbone-validation': '/public/js/lib/backbone-validation'
}
});
require(
[
'order!jquery',
'order!jquerymx',
'order!bootstrap',
'order!handlebars',
'order!underscore',
'order!backbone',
'order!backbone-validation'
], function () {

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


is there something wrong here?

Thanks.

Answer

A few suggestions:

First, the order plugin is no longer supported or necessary in RequireJS 2.0. The shim configuration is fully capable of expressing what you need to do. See here for details.

Second, I'm a little confused why you have both jquery and jquery.min listed as dependencies. They should provide the exact same thing, with jquery.min just being a smaller file. Some JS can get confused when you pull in the same code twice, which might be what's happening here. Try removing all instances of jquery.min from your configuration.

Finally, your two-phased require(...) call doesn't appear to be necessary. Assuming your main module lists the libraries it needs directly, you should be able to just do:

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

If the above suggestions don't help, please provide more details -- i.e. what is in the main module.

Comments