Backbone.js and Require.js: Mismatched anonymous define() module: function (_, Backbone) {

不打扰是莪最后的温柔 提交于 2019-12-10 19:09:45

问题


I am new to using require.js and have the following app.js file as part of my backbone app:

require.config({
baseUrl: "/js/",
paths: {
    jquery: 'libs/jquery-2.1.0',
    underscore: 'libs/underscore-min',
    backbone: 'libs/backbone-min'
},
shim: {
    underscore: {
        exports: "_"
    },
    backbone: {
        deps: ['underscore', 'jquery'],
        exports: 'Backbone'
    },
}
});

In a tag in my index.html file, I have placed the following:

define(['underscore', 'backbone'], function (_, Backbone) {

However, I am getting the following error my index.html file:

Uncaught ReferenceError: Backbone is not defined

And the following in my require.js file:

Uncaught Error: Mismatched anonymous define() module: function (_, Backbone) {

Any clues?


回答1:


I'm using the config above,

As you can see comparing my sample image with you way to declare, is there minimals diffs:

  • You don't need to declare shim libs at paths, just use the same name;
  • My baseUrl starts on my js\lib folder;
  • I'm using file name on my json config;

When I declare the "setup" on my main html page I'm using like that:

<script data-main="js/setup.js" src="js/lib/require.js"></script>


来源:https://stackoverflow.com/questions/23143506/backbone-js-and-require-js-mismatched-anonymous-define-module-function-b

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