未捕获的错误:不匹配的匿名定义()模块:函数定义(名称,全局) [英] 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:
define([
'jquery',
'underscore',
'backbone'
],function(){
subAccountRouter = Backbone.Router.extend({
routes: {
// Defining the routes
'sub-accounts': 'subAccountList',
'*actions': 'defaultAction'
},
});
似乎对 requirejsdefine() 调用函数进行了一些更改,不知何故无法弄清楚.有人有想法吗??
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
我在这里做错了什么??我检查了我的所有路径,它们似乎是正确的,我仍然不明白为什么这个问题仍然困扰着我..:(我尝试更改路由的路径,并将参数传递给 function($, _, Backbone)
(如下面的 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???
推荐答案
UPDATE
检查文档后 - 这实际上是他们讨论的第一个错误:
After checking the docs - this is actually the first error they discuss:
如果您在 HTML 中手动编写脚本标记以使用匿名define() 调用加载脚本,则可能会发生此错误."
"If you manually code a script tag in HTML to load a script with an anonymous define() call, this error can occur."
因此,请确保 index.html 中唯一的 标记(至少对于调用
define()
的任何脚本而言)是 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.
结束更新
您需要像这样将参数传递给您的 function()
:
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屋!