Uncaught Error: Bootstrap's JavaScript requires jQuery with requirejs

萝らか妹 提交于 2020-01-14 05:42:05

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/29316204/uncaught-error-bootstraps-javascript-requires-jquery-with-requirejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!