requirejs: Module name “underscore” has not been loaded yet for context [duplicate]

岁酱吖の 提交于 2019-12-10 08:17:56

问题


I always get this error when I freshly load my app,

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({

But then they are gone when I hit the refresh button on my browser.

Does anyone know why? How can I fix it?

This is my config/ main/ entry js file,

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();
});

Have I missed something?


回答1:


try this:

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


来源:https://stackoverflow.com/questions/20311260/requirejs-module-name-underscore-has-not-been-loaded-yet-for-context

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