简体   繁体   中英

Intermittent “Bootstrap's JavaScript requires jQuery” error

I've just started using requirejs and I'm having a problem that I can't seem to solve. I am occasional getting error "Bootstrap's JavaScript requires jQuery" when I load my application. Here are the pertinent files:

.HTML

<html>
<head>
<link href="./css/bootstrap.min.css" rel="stylesheet">
<link href="./css/custom.css" rel="stylesheet">
<script data-main="scripts/main" src="scripts/vendor/require.js"></script>
</head>
<body>
...
</body>

my require.config from main.js file:

requirejs.config({
    baseUrl : './scripts',
    shim : {
        underscore : {
            exports : '_'
        },

        bootstrap : {
            dep : [ 'jquery'],
            exports: 'Bootstrap'
        },

        backbone : {
            deps : [ 'jquery', 'underscore' ],
            exports : 'Backbone'
        },

        marionette : {
            deps : [ 'jquery', 'underscore', 'backbone' ],
            exports : 'Marionette'
        },

        text: {
            deps : [ 'jquery', 'underscore', 'backbone' ],
            exports: 'Text'
        }
    },

    paths : {
        jquery : 'vendor/jquery.min',
        underscore : 'vendor/underscore',
        bootstrap : 'vendor/bootstrap.min',
        backbone : 'vendor/backbone',
        marionette : 'vendor/backbone.marionette',
        text: 'vendor/text'
    }
});

As I say, this doesn't happen all the time, just randomly. Can someone see what I'm doing wrong or how I might be able to track down the problem?

Thanks

In this part of your config:

bootstrap : {
            dep : [ 'jquery'],

It should be deps not dep . With dep , it is as if you had not specified any dependencies at all, which means that Bootstrap will load fine only if jQuery happens to be loaded before it. (Also, Bootstrap does not define a Bootstrap symbol so the exports bit is useless.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM