ReferenceError:未定义 DartObject
Posted
技术标签:
【中文标题】ReferenceError:未定义 DartObject【英文标题】:ReferenceError: DartObject is not defined 【发布时间】:2014-02-24 20:59:31 【问题描述】:我的 dart2js 编译的 Chrome 打包应用程序因 Uncaught Error: Instance of 'UnknownjavascriptObject'
和 ReferenceError: DartObject is not defined
而崩溃。
完整的堆栈跟踪如下
Uncaught Error: Instance of 'UnknownJavaScriptObject' echo_mco.dart.js:7913
Stack Trace:
ReferenceError: DartObject is not defined
at dart._convertToDart (chrome-extension://paadaccdfibbhkkhjaolagidoopakdik/echo_mco.dart.js:7422:34)
at JsObject.$index (chrome-extension://paadaccdfibbhkkhjaolagidoopakdik/echo_mco.dart.js:7449:16)
at dart.J.$index$asx (chrome-extension://paadaccdfibbhkkhjaolagidoopakdik/echo_mco.dart.js:8496:41)
at chrome-extension://paadaccdfibbhkkhjaolagidoopakdik/echo_mco.dart.js:8874:12
at Isolate.prototype.(anonymous function) (chrome-extension://paadaccdfibbhkkhjaolagidoopakdik/echo_mco.dart.js:9412:37)
at chrome-extension://paadaccdfibbhkkhjaolagidoopakdik/echo_mco.dart.js:8871:25
at Isolate.prototype.(anonymous function) (chrome-extension://paadaccdfibbhkkhjaolagidoopakdik/echo_mco.dart.js:9412:37)
at RawDatagramSocket_bind_closure.call$0 (chrome-extension://paadaccdfibbhkkhjaolagidoopakdik/echo_mco.dart.js:3079:14)
at dart.Future_Future$sync (chrome-extension://paadaccdfibbhkkhjaolagidoopakdik/echo_mco.dart.js:3381:28)
at dart.RawDatagramSocket.static.RawDatagramSocket_bind (chrome-extension://paadaccdfibbhkkhjaolagidoopakdik/echo_mco.dart.js:3070:18)
【问题讨论】:
【参考方案1】:这是由于未正确包含 interop.js
脚本造成的。它必须包含在
<script src="packages/browser/interop.js"></script>
并且它必须在所有其他与 Dart 相关的 JavaScript 包括之前。所以包含可能看起来像这样
<script src="packages/browser/interop.js"></script>
<script type="application/dart">export 'package:polymer/init.dart';</script>
<script src="packages/browser/dart.js"></script>
在使用 chrome 包的 Chrome 打包应用程序中,包含的内容可能如下所示
<script src="packages/browser/interop.js"></script>
<script src="packages/chrome/bootstrap.js" defer></script>
<script src="echo_mco.dart" type="application/dart"></script>
问题正在https://code.google.com/p/dart/issues/detail?id=15065讨论和解决
【讨论】:
以上是关于ReferenceError:未定义 DartObject的主要内容,如果未能解决你的问题,请参考以下文章
打字稿 - 未捕获的 ReferenceError:未定义导出
JavaScript Uncaught ReferenceError: jQuery is not defined;未捕获的 ReferenceError:$ 未定义 [重复]