最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

requirejs - Intermittent "Bootstrap's JavaScript requires jQuery" error - Stack Overflow

programmeradmin5浏览0评论

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

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

Share Improve this question edited May 22, 2014 at 18:40 idbehold 17.2k5 gold badges48 silver badges74 bronze badges asked May 22, 2014 at 18:02 DaveRDaveR 1,4452 gold badges16 silver badges37 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 12

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.)

发布评论

评论列表(0)

  1. 暂无评论