I have a Polymer component that's referenced by other components. Something like:
In index.html
<link rel="import" href="lib/polymer/polymer.html">
<link rel="import" href="component-one.html">
...
<component-one></component-one>
In component-one.html
<link rel="import" href="sub-component.html">
<dom-module id="component-one">
<template>
<sub-component></sub-component>
</template>
<script>Polymer({ is: 'component-one' });</script>
</dom-module>
In component-two.html
<link rel="import" href="sub-component.html">
<dom-module id="component-two">
<template>
<sub-component></sub-component>
</template>
<script>Polymer({ is: 'component-two' });</script>
</dom-module>
In sub-component.html
<dom-module id="sub-component">
<template>blah blah blah</template>
<script>Polymer({ is: 'sub-component' });</script>
</dom-module>
The problem comes in when I attempt to dynamically load the second component in index.html:
function importHref(href) {
return new Promise((resolve, reject) => {
Polymer.Base.importHref(href, function (e) {
resolve(e.target);
}, reject, true);
});
}
...
await importHref('component-two.html');
// Now I can use <component-two>
This throws an exception:
Uncaught DOMException: Failed to execute 'registerElement' on 'Document': Registration failed for type 'sub-component'. A type with that name is already registered.
I figure this is happening due to sub-component.html being referenced by two components, but both also reference lots of paper and iron elements and none of them cause this error.
How to I avoid this exception?