无法使用聚合物元素 - “无法在'文档'上执行'registerElement'" [英] Can't Use Polymer Element - "Failed to execute 'registerElement' on 'Document'"

查看:66
本文介绍了无法使用聚合物元素 - “无法在'文档'上执行'registerElement'"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个元素,为了简洁起见,我将在此简化,我想做一个端到端的过程,看看它是否有效。

I created an element which which I'll simplify here for brevity, and I wanted to do an end-to-end process and see if it works.

这是它的bower.json文件:

This is its bower.json file:

{
  "name": "test-element",
  "version": "0.0.1",
  "authors": [
    "my name"
  ],
  "description": "A description",
  "license": "MIT",
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components",
    "test",
    "tests"
  ],
  "dependencies": {
    "polymer": "~0.9.0"
  }
}

我上传到我的测试回购,并在WebStorm开设了一个新项目。

I uploaded it to my test repo, and opened a new project in WebStorm.

我做了 bower install test-element ,它还下载了聚合物目录,这是我想要的依赖项,虽然那里没有js文件。 (不应该有 polymer.js 文件来引用?)

I did bower install test-element and it also downloaded the polymer directory which is the dependency, as I wanted, though there are no js files there. (Shouldn't there be a polymer.js file to reference?)

现在,我的索引文件加载了在身体中有这个:

Now, my index file that loads has this in the body:

    <script src="bower_components/webcomponentsjs/webcomponents.js"></script>
    <link rel="import" href="bower_components/test-element/test-element.html">

    <test-element
        elements="[...array contents...]">
    </test-element>

我的 test-element.html

<link rel="import" href="../../../polymer/polymer.html">


<polymer-element name="test-element" ....> 
    <template>
          ... doesn't really matter ...
    </template>
    <script>
        Polymer({
            created: function () { .. }
        });
    </script>
</polymer-element>

但是当我加载页面时,我在控制台中看到了这一点:

But when I load the page I see this in the console:


未捕获的SyntaxError:无法在
'Document'上执行'registerElement':类型'undefined'的注册失败。类型名称是
无效。

Uncaught SyntaxError: Failed to execute 'registerElement' on 'Document': Registration failed for type 'undefined'. The type name is invalid.

我试了很多帖子,我看不到我在这里缺少什么。我在导入元素的HTML文件之前加载 webcomponents.js

I tried many posts, and I can't see what I'm missing here. I'm loading the webcomponents.js before importing the element's HTML file.

所以2个问题:


  1. 为什么会出现此错误,我做错了什么?我错过了 polymer.js 吗?如果是这样,为什么不下载作为依赖项的一部分?

  2. 如果我有很多元素,我是否需要包含 polymer.html 在每个中或者我可以在 index.html 文件中加载一次吗?

  1. Why does this error occur and what did I do wrong? Am I missing the polymer.js ? If so, why didn't it download as part of the dependency ?
  2. If I have many elements, do I need to include the polymer.html in each of them or can I just load it once in the index.html file?


推荐答案


  1. 您正在将聚合物0.5与0.9混合。 Polymer 0.9中发生了很多变化。例如,聚合物元件已被dom模块取代。 迁移指南。

  1. You are mixing polymer 0.5 with 0.9. A lot has changed in Polymer 0.9. Eg., polymer-element has been replaced with dom-module. Migration Guide.

之前:

<polymer-element name="register-me">
  <template>
    <div>Hello from my local DOM</div>
  </template>
  <script>
    Polymer();
  </script>
</polymer-element>

之后:

<dom-module id="register-me">
  <template>
    <div>Hello from my local DOM</div>
  </template>
</dom-module>

<script>
  Polymer({is: "register-me"});
</script>




  1. 您看到此错误




未捕获的SyntaxError:无法在
'Document'上执行'registerElement':类型'undefined的注册失败。类型名称是
无效。

Uncaught SyntaxError: Failed to execute 'registerElement' on 'Document': Registration failed for type 'undefined'. The type name is invalid.

因为您使用的聚合物核心元素与Polymer 0.5和Polymer 0.9兼容。与聚合物0.9一起,聚合物元素也得到升级。按照发布安装新元素。

because you are using polymer core elements that are compatible with Polymer 0.5 with Polymer 0.9. Along with polymer 0.9 the polymer elements are also upgraded. Follow this post to install the new elements.

注意:核心元素在聚合物0.9中报废,并用铁元素替代。


  1. 要正确安装Polymer 0.9,请在您的bower.json中包含这些行

  1. To properly install Polymer 0.9 include these lines in your bower.json

依赖:{
聚合物:聚合物/聚合物#^ 0.9.0
}

并使用此终端命令 $ bower install

这篇关于无法使用聚合物元素 - “无法在'文档'上执行'registerElement'&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆