加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

使用Paper-Input时,Polymer 3.0 Uncaught DOM异常

发布时间:2020-12-14 18:34:12 所属栏目:资源 来源:网络整理
导读:使用纸张输入时,导入会引发以下异常 Uncaught DOMException: Failed to execute ‘define’ on ‘CustomElementRegistry’: this name has already been used with this registry. 除了为3.0创建模板并添加导入之外,我还没有做任何事情. 迁移工具似乎存在问
使用纸张输入时,导入会引发以下异常

Uncaught DOMException: Failed to execute ‘define’ on ‘CustomElementRegistry’: this name has already been used with this registry.

除了为3.0创建模板并添加导入之外,我还没有做任何事情.

迁移工具似乎存在问题,Google曾用它来更新旧组件.

有没有人对此进行排序?

解决方法

更新问题是由node_modules中的两个不同版本的iron-meta引起的:./node_modules/@polymer/iron-meta中的旧版本3.0.0-pre.18(已经与Polymer Starter Kit一起安装),以及较新的(3.0.0-pre.19)作为新安装的@聚合物/纸张输入的依赖.

最近在Polymer Blog中记录了该修复程序 – 即删除package-lock.json并重新安装node_modules:

rm -rf node_modules package-lock.json
npm install

错误的堆栈跟踪(下面)似乎表明iron-meta以某种方式注册了两次:

polymer-fn.js:43 Uncaught (in promise) DOMException: Failed to execute 'define' on 'CustomElementRegistry': this name has already been used with this registry
    at Polymer (http://127.0.0.1:8081/node_modules/@polymer/polymer/lib/legacy/polymer-fn.js:43:18)
    at http://127.0.0.1:8081/node_modules/@polymer/iron-input/node_modules/@polymer/iron-meta/iron-meta.js:131:1

一种解决方法是将customElements.define修补为仅在尚未定义元素时运行:

const _customElementsDefine = window.customElements.define;
window.customElements.define = function(name,clazz,config) {
  if (!customElements.get(name)) {
    _customElementsDefine.call(window.customElements,name,config);
  }
};

在导入任何元素定义之前运行它.我确认这适用于最新版本的macOS High Sierra,Chrome 66上的纸张输入.

链接您创建的问题以供参考:PolymerElements/paper-input Issue #652

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读