requirejs: Module name “underscore” has not been l

2019-05-07 21:53发布

This question already has an answer here:

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?

enter image description here

1条回答
狗以群分
2楼-- · 2019-05-07 22:18

try this:

shim: {
        jquery: {
          exports: '$'
        },
        underscore: {
          deps:["jquery"],
          exports: '_'
        },
        backbone: {
          deps:["jquery"],
          exports: 'Backbone'
        }
      }
查看更多
登录 后发表回答