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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With