requirejs:尚未为上下文加载模块名称“下划线”

时间:2013-12-01 10:42:03

标签: javascript jquery backbone.js requirejs underscore.js

当我刚刚加载我的应用时,我总是收到此错误,

Error: Module name "underscore" has not been loaded yet for context:
_. Use require([]) http://requirejs.org/docs/errors.html#notloaded  

...,h){c=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);c.requireType=b;c.re...

require.js (line 8) TypeError: Backbone.Model is undefined  

var ProjectModel = Backbone.Model.extend({

但是当我点击浏览器上的刷新按钮时,它们就消失了。

有谁知道为什么?我该如何解决?

这是我的config / main / entry js文件,

require.config({
    //By default load any module IDs from js/lib
    baseUrl: 'js',

    paths: {
        jquery: 'lib/jquery/jquery-min',
        underscore: 'lib/underscore/underscore-min',
        backbone: 'lib/backbone/backbone-min',
        text: 'lib/text/text'
    },

    shim: {
        jquery: {
          exports: '$'
        },
        underscore: {
          exports: '_'
        },
        backbone: {
          exports: 'Backbone'
        }
      }
});

require([
    // Load our app module and pass it to our definition function
    'app',
    'jquery',
    'underscore',
    'backbone',

    // Pull in the Collection module.
    'collection/contacts'
], function(App){
    // The "app" dependency is passed in as "App"
    App.initialize();
});

我错过了什么吗?

enter image description here

1 个答案:

答案 0 :(得分:4)

试试这个:

shim: {
        jquery: {
          exports: '$'
        },
        underscore: {
          deps:["jquery"],
          exports: '_'
        },
        backbone: {
          deps:["jquery"],
          exports: 'Backbone'
        }
      }