未捕获的HierarchyRequestError

时间:2014-08-07 19:35:47

标签: dart dart-polymer

我是飞镖和聚合物的初学者。当我在Chrome中运行网络应用时,我得到:

Uncaught HierarchyRequestError: Failed to execute 'appendChild' on 'Node': Nodes of type 'HTML' may not be inserted inside nodes of type '#document'. patches-mdv.js:57
(anonymous function) patches-mdv.js:57
(anonymous function) patches-mdv.js:57
(anonymous function) patches-mdv.js:57

appendChild可能是生成的dart2js代码,即以下部分:

  Node: {
    "^": "EventTarget;ownerDocument=,text:textContent=",
    remove$0: function(receiver) {
      var t1 = receiver.parentNode;
      if (t1 != null)
        J._removeChild$1$x(t1, receiver);
    },
    toString$0: function(receiver) {
      var t1 = receiver.nodeValue;
      return t1 == null ? J.Interceptor.prototype.toString$0.call(this, receiver) : t1;
    },
    append$1: function(receiver, newChild) {
      return receiver.appendChild(newChild);
    },
    insertBefore$2: function(receiver, newChild, refChild) {
      return receiver.insertBefore(newChild, refChild);
    },
    _removeChild$1: function(receiver, oldChild) {
      return receiver.removeChild(oldChild);
    },
    _replaceChild$2: function(receiver, newChild, oldChild) {
      return receiver.replaceChild(newChild, oldChild);
    },
    $isNode: true,
    "%": "DocumentType|Notation;Node"
  },

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:5)

https://groups.google.com/a/dartlang.org/forum/#!msg/web/bgMajiu_iR4/rygd5Ftk668J所述,根据症状,看起来platform.js已加载两次。

除了你的toplevel index.html之外,从每个html中删除以下两行:

<script src="packages/web_components/platform.js"></script>
<script src="packages/web_components/dart_support.js"></script>

更新: 用聚合物&gt;不再需要0.14.0 platform.js。它由pub buildpub serve自动添加。