简体   繁体   English

Dojo.js AMD Loader-TypeError:无法将未定义转换为对象

[英]Dojo.js AMD Loader - TypeError: can't convert undefined to object

I looked for duplicate questions, but did not find one exactly. 我寻找了重复的问题,但没有完全找到一个问题。 This is related to Dojo require() and AMD (1.7) , but I will ask in the form of a question. 这与Dojo require()和AMD(1.7)有关 ,但是我将以问题的形式提出。 The question is, why am I getting this error and why is dijit showing '3' in firebug? 问题是,为什么我会收到此错误?为什么dijit在Firebug中显示“ 3”?

The JSP Page JSP页面

<script type="text/javascript" src="<%= request.getContextPath() %>/js/dojoConfig.js"></script>
<script type="text/javascript"
src="http://xxxxxxxxxxxxx.com/dojo/1.7.2/dojo/dojo.js.uncompressed.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/js/reviewframe.js"></script>

dojoConfig.js dojoConfig.js

var dojoConfig = {
// Use the Asynchronous AMD loader.
// --------------------------------
async : true,
// Use debug.
// --------------------------------
isDebug : true,
// Parse the html on load for dojo rendered elements.
// Don't Parse on Load. I'm calling it manually in my main pageLoad.
// --------------------------------
parseOnLoad : false,
};

reviewframe.js (My 'main') reviewframe.js(我的“主要”)

require(
[ "dojo", "dijit", "dojo/parser", "js/XYDialog.js",
"dijit/layout/ContentPane", "dojox/image/LightboxNano", "dojo/ready",
"dojo/domReady!" ],
function(dojo, dijit, parser, XYDialog) {

XYDialog.js XYDialog.js

define([ "dojo", "dijit", "dijit/form/Button", "dijit/TooltipDialog",
    "dijit/form/DropDownButton", "dijit/form/FilteringSelect" ], function(
    dojo, dijit) {

I set a breakpoint on the define above in XYDialog.js. 我在上面的XYDialog.js中的定义上设置了一个断点。 I hit continue and I get this error in the console: 我点击继续,然后在控制台中收到此错误:

console 安慰

focus.js line 382
TypeError: can't convert undefined to object [Break On This Error]  ...attr] = typeof singleton[attr] == "function" ? lang.hitch(singleton, attr) : sin...

If I set a Firebug breakpoint in focus.js right before that line, I see that dijit is the number 3. Why? 如果我在该行之前在focus.js中设置一个Firebug断点,我会看到dijit是数字3。为什么? I have seen this before in other places where the javascript or modules I require end up being the number 3. 我之前在其他我需要的javascript或模块最终为数字3的地方看到过这一点。

EDIT: OMG, I closed Firefox and loaded the page w/o firebug. 编辑:天哪,我关闭了Firefox并加载了没有萤火虫的页面。 It works! 有用! Then I opened firebug, cleared all breakpoints and it works again. 然后,我打开了萤火虫,清除了所有断点,然后再次起作用。 Sheesh. 啧。

Follow up question: Can breakpoints in firebug screw up the AMD loader? 后续问题: firebug中的断点会破坏AMD加载程序吗? It is asynchronous after all. 毕竟它是异步的。 Your breakpoint may introduce a timing issue... 您的断点可能会引入计时问题...

There are two issues here: 这里有两个问题:

  1. You are loading an AMD module using the file name rather than the module ID (XYDialog.js), so it is being treated and loaded as a non-AMD module. 您正在使用文件名而不是模块ID(XYDialog.js)加载AMD模块,因此将其视为非AMD模块并将其加载。 You should either put it in a logical package, or define the path in your config, eg: 您应该将其放在逻辑包中,或者在配置中定义路径,例如:

    file structure: 文件结构:

     /js/foo/XYDialog.js /js/dojo/dojo.js 

    code: 码:

     // reviewframe.js (My 'main') require( [ "dojo", "dijit", "dojo/parser", "foo/XYDialog", 
  2. The cryptic code "3" usually refers to an incorrect path to a package. 密码“ 3”通常表示错误的软件包路径。 I believe the first issue, combined with Firebug, may be inconsistently giving you this error. 我认为第一个问题与Firebug结合使用可能会不一致地给您这个错误。

See the note under http://www.sitepen.com/blog/2012/10/31/debugging-dojo-common-error-messages/#incorrect-package-path (this article in general is one we wrote that will help you identify the cause of the most common error messages when using Dojo and AMD). 请参阅http://www.sitepen.com/blog/2012/10/31/debugging-dojo-common-error-messages/#incorrect-package-path下的注释(这篇文章通常是我们写的,对您有所帮助您可以确定使用Dojo和AMD时最常见错误消息的原因)。

重新启动Firefox并清除Firebug中的断点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM