未被捕获的错误:不匹配的匿名定义()模块:函数定义(名称,全局) [英] Uncaught Error: Mismatched anonymous define() module: function definition(name, global)
问题描述
我加载的骨干requirejs文件得到这个错误。我试着加载r.js的requirejs优化,但我还是坚持了下来。
I got this error while loading the requirejs file for the backbone. I tried loading the r.js, the requirejs optimizer, but I'm still stuck with it.
Uncaught Error: Mismatched anonymous define() module: function definition(name, global){
"use strict";
var PubSub = {
name: 'PubSubJS',
version: '1.3.1-dev'
以下是我的js:
Following is my js:
define([
'jquery',
'underscore',
'backbone'
],function(){
subAccountRouter = Backbone.Router.extend({
routes: {
// Defining the routes
'sub-accounts': 'subAccountList',
'*actions': 'defaultAction'
},
});
似乎已经有过requirejs做了一些改动定义()函数调用,不知何故着的数字出来。没有任何人有想法?
Seems there have been some changes made to requirejs define() call function, somehow cant figure it out. Does anyone have ideas??
::
下面是router.js文件。
Below is the router.js file.
define([
'jquery',
'underscore',
'backbone'
],function($, _, Backbone){
SubAccountRouter = Backbone.Router.extend({
routes: {
'sub-accounts': 'subAccountList',
'*actions': 'defaultAction'
},
initialize: function () {
this.appContainer = $("#subaccount");
//collections and models
this.subAccountCollection = null;
this.subAccountModel = null;
},
subAccountList: function(){
var self = this;
},
defaultAction: function(){
this.subAccountList();
},
});
return {
initialize: function() {
Backbone.history.start();
}
};
}); //main func
我做什么我错了这里?
我检查我的人的路径,他们似乎是正确的,我仍然不明白为什么这个问题仍然缠着我.. :(
我曾试图改变路径,路由,同时也传递参数给函数($,_,骨干)
(如sol'n 1图所示)。不过,我似乎仍然看到错误。没有任何一个有任何其他的想法?
What im i doing wrong here??
I check al my paths and they seem to be correct, i still dont get why this issue is still bugging me..:(
I have tried changing the paths for the routes, and also passing arguments to the function($, _, Backbone)
(as shown below in 1 of the sol'n). However i still seem to see the error. Does any one have any other ideas???
推荐答案
更新
检查后的文档 - 这其实是他们讨论的第一个错误:
After checking the docs - this is actually the first error they discuss:
如果你手动code在HTML的脚本标记加载脚本与匿名定义()调用,可能会出现这种错误。
"If you manually code a script tag in HTML to load a script with an anonymous define() call, this error can occur."
所以要确保只有<脚本>
标签(至少其中要求定义()的脚本
)在您的index.html是一个requirejs。
So make sure the only <script>
tag (at least for any scripts which call define()
) in your index.html is the one to requirejs.
END更新的
END UPDATE
您需要参数传递给你的函数()
像这样:
You need to pass in parameters to your function()
like so:
define([
'jquery',
'underscore',
'backbone'
],function(jquery, underscore, backbone){
subAccountRouter = Backbone.Router.extend({
routes: {
// Defining the routes
'sub-accounts': 'subAccountList',
'*actions': 'defaultAction'
},
});
我写了一篇关于最近设立requirejs一个超简单的后如果你还是卡住了。
I wrote a super-simple post on setting up requirejs recently, if you're still stuck.
这篇关于未被捕获的错误:不匹配的匿名定义()模块:函数定义(名称,全局)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!