繁体   English   中英

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

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

我寻找了重复的问题,但没有完全找到一个问题。 这与Dojo require()和AMD(1.7)有关 ,但是我将以问题的形式提出。 问题是,为什么我会收到此错误?为什么dijit在Firebug中显示“ 3”?

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

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(我的“主要”)

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

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

我在上面的XYDialog.js中的定义上设置了一个断点。 我点击继续,然后在控制台中收到此错误:

安慰

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...

如果我在该行之前在focus.js中设置一个Firebug断点,我会看到dijit是数字3。为什么? 我之前在其他我需要的javascript或模块最终为数字3的地方看到过这一点。

编辑:天哪,我关闭了Firefox并加载了没有萤火虫的页面。 有用! 然后,我打开了萤火虫,清除了所有断点,然后再次起作用。 啧。

后续问题: firebug中的断点会破坏AMD加载程序吗? 毕竟它是异步的。 您的断点可能会引入计时问题...

这里有两个问题:

  1. 您正在使用文件名而不是模块ID(XYDialog.js)加载AMD模块,因此将其视为非AMD模块并将其加载。 您应该将其放在逻辑包中,或者在配置中定义路径,例如:

    文件结构:

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

    码:

     // reviewframe.js (My 'main') require( [ "dojo", "dijit", "dojo/parser", "foo/XYDialog", 
  2. 密码“ 3”通常表示错误的软件包路径。 我认为第一个问题与Firebug结合使用可能会不一致地给您这个错误。

请参阅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