我已经阅读了以前的线程,其中其他成员有与我相同的错误消息,但他们接受的解决方案似乎没有帮助。
基本上,当我尝试加载 index.html 时,我在 Chrome 控制台中得到了这个:
Uncaught Error: Module name "underscore" has not been loaded yet for context: _. Use require([])
几秒钟后,这出现了:
Uncaught Error: Load timeout for modules: underscore,backbone
在 day_view.js 加载正常(200 OK)之前,Chrome 网络工具不会显示任何异常。
文件结构
索引.html
...
<script>
var require = {
deps: ["jquery/jquery-min", "underscore/underscore-min", "backbone/backbone-min"]
};
</script>
<script data-main="scripts/main" src="scripts/require.js"></script>
...
main.js
require.config({
baseUrl: 'scripts',
paths:{
jquery:'jquery/jquery-min',
underscore:'underscore/underscore-min',
backbone:'backbone/backbone-min'
},
shim: {
underscore: {
exports: '_'
},
backbone: {
deps: ["underscore/underscore-min", "jquery/jquery-min"],
exports: "Backbone"
}
},
waitSeconds: 200
});
require(['day_view'], function (day_view) {
function start() {
day_view.render();
}
return {
start:start
};
});
day_view.js
define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {
function render() {
...
}
...