未捕获的DOMException:无法在'CustomElementRegistry'上执行'define':此名称已与该注册表一起使用 [英] Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': this name has already been used with this registry

查看:872
本文介绍了未捕获的DOMException:无法在'CustomElementRegistry'上执行'define':此名称已与该注册表一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

未捕获的DOMException:无法在'CustomElementRegistry'上执行'define':此名称已与该注册表一起使用 在 http://127.0. 0.1:8000/components/@polymer/polymer/lib/elements/dom-module.js:175:16

Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': this name has already been used with this registry at http://127.0.0.1:8000/components/@polymer/polymer/lib/elements/dom-module.js:175:16

尝试删除节点模块和程序包锁定并重新安装无效.

Tried deleting node-modules and package-lock and reinstalling did not work.

推荐答案

对于那些正在注册的自定义元素,只需检查一下尚未注册使用该名称的元素即可.显然,您可以包括更复杂的逻辑来更改名称,装饰类等,但这只是检查是否已使用现有的API注册了某些东西,如果没有,则注册给定的东西(按照我的风格,您可以改变,这只是说明如何通常避免该错误):

For those cases where it's a custom element you're registering simply check that an element by this name hasn't already been registered. Obviously you can include more complex logic to vary the name, decorate the class, etc, however this simply checks to see if something is already registered using the existing API and if not, registers the given thing (in my style--yours can vary, this is simply showing how to generally avoid the error):

customElements.get('the-element') || customElements.define('the-element', HTMLTheElement);

有关API的更多信息,请参见 https://developer.mozilla. org/zh-CN/docs/Web/API/CustomElementRegistry

For more on the API see https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry

这篇关于未捕获的DOMException:无法在'CustomElementRegistry'上执行'define':此名称已与该注册表一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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