问题
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
shimlibs atpaths, just use the same name; - My baseUrl starts on my
js\libfolder; - 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