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.
this error is due to a custom element tag-name being registered which is already registered; to fix simply check that an element by this name hasn't already been registered. This example solution checks to see if something is already registered using the existing API and if not, registers the given Class (inheriting from/extending HTMLElement--at some point):
customElements.get('the-element') || customElements.define('the-element', HTMLTheElement);
For more on the API see https://developer.mozilla.org/docs/Web/API/CustomElementRegistry
most/mature libraries address this problem and those that don't, or are mangled by package and build process complexities can have it pop up; in most cases either updating to a current version, migrating to Lit (https://lit.dev) or patching the problem somehow provides a path to a solution; note the simpler solutions are far easier to maintain--as can be seen in the conflation of npm, polymer over the actual error in the original question; the Polymer project became lit-html and LitElement, and recently rebranded as "Lit" (and still includes these lit-things). Professionally I'm migrating away from npm and Nodejs to Deno with the aim of generally resolve the many problems related to npm and tooling insecurity and complexity, however this answer provides a more direct solution (understand the problem and fix directly, or update to the relevant latest solution which includes this somehow).
Well, this worked for me, with no Typescript warnings,
if (!customElements.get('the-element')) { customElements.define('the-element', HTMLTheElement); }
Hope someone will find this useful.
Cheers.
It is unwise to use the answers above. You want it to fail! The reason being is that your NPM should be deduping duplicate packages, so the fact that you see a certain component being defined on the custom elements registry more than once is a crucial error that you need to debug why the same component is registered more than once.
How to debug, in short, go to your browser, inspect element, network tab, refresh, figure out which files are both registering the same element. Then check in the initiator to see which files are loading those files. Then you get a way better idea of why your app is not resolving the same import to a single place (your deduped dependency).
One reason why you might face this problem is due to semver. If you have multiple different major versions of the same dependency, NPM cannot just dedupe all of the installations to your root node_modules. How you solve this is up to you. Some people use npm-aliases for their different majors of a dependency, some people implement a plugin in their build-tool to resolve paths to a single installation, etc.
For people that can't use #jimmonts answer because the issue is in one of their dependencies you can use the following snippet:
This happens for us, because a package we are using defines an element. But this package is used by multiple apps. And these apps, wouldn't you know it, interact. So customElements.define('x-tag', className) gets called multiple times. And the second time it does, it crashes the app.
function safeDecorator(fn) {
// eslint-disable-next-line func-names
return function(...args) {
try {
return fn.apply(this, args);
} catch (error) {
if (
error instanceof DOMException &&
error.message.includes('has already been used with this registry')
) {
return false;
}
throw error;
}
};
}
customElements.define = safeDecorator(customElements.define);
I was getting the same error. You may not have the same issue as me but I thought I would drop my solution here just incase someone runs into the same issue in the future.
I had two modules that both imported the same custom element module, one of the was importing Module.js and the other module.js. Now the browser saw this as two separate files because URLs can be case sensitive, except my server saw this as one file because it is not case sensitive (express.js) or at least it was able to resolve the path to the correct file even with the incorrect case. And so the browser saw two "different" modules both defining the same custom element, but when I searched my source code only one file was defining the custom element.
I had this problem and found out that I was calling on my boundle.js file twice. Since I was using Webpack and HtmlWebpackPlugin, HtmlWebpackPlugin added the reference to my boundled file to my index.html file where I had already referenced it by hand.
I developed a solution, thats overrite the define with a precheck before define. It works fine for me, just ad the 2 lines into your index.js
customElements.defineclone = Object.assign(Object.create(Object.getPrototypeOf(customElements)).define, customElements);
customElements.define = (name, element) => customElements.get(name) || customElements.defineclone(name, element);
My goal is to have a class which can find any tests written in kotlintest. I already have working code for Java/Scala/Groovy unit tests but can't get it to work for Kotlintest.
My discover code:
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(selectPackage("com.example")).build();
descriptor = new KotlinTestEngine().discover(request, uniqueId);
UniqueId has value of "engine:junit-example". I tried adding the following code but it doesn't work either.
new DiscoverySelectorResolver().resolveSelectors(discoveryRequest, descriptor);
The descriptor contains all the classes with tests but no test methods. In other cases it is enough to call descriptor.getChildren() to get the test methods but with Kotlintest I get empty list.
Thanks for any help.
The reason your code doesn't work is because KotlinTest doesn't honour package name selectors. This could be considered a bug in KotlinTest.
It does honour classpath, class, directory and uri selectors though.
Edit:
As of 3.2 KotlinTest now supports package selectors so your code will work.
I am trying to configure a spring-ldap context source and I find the following example in the documentation:
<ldap:context-source
username="cn=Administrator"
password="secret"
url="ldap://localhost:389"
base="dc=261consulting,dc=com" />
I would like to be able to specify the userid/password and, if possible, the url and port elsewhere (like a JNDI reference from a datasource). I can't find any context source example or spec in the documentation (or in google) that has this sort of configuration. Can I do it and how?
Beyond using a properties file, no.
You can instantiate the class: org.springframework.ldap.core.support.LdapContextSource internally in your application and then set the values: url, base, userDn, password, referral, etc.
In the spring-ldap samples you will find how to use it. Here is an example!
I hope it helps!
i am new in adobe cq5 .I created a page test in my repository inside the
content node of page.I have 100 nodes example test-1 , test-2,test-3....test-100.I want to retrieve the selected properties of these nodes like name , modification date etc.How can i achieve this ? can anybody help regarding this.
From your question title, you want to get a JSON representation of your nodes. This is a built in feature (which should be blocked on the dispatcher though):
Just add .X.json to your path whereas X is a the depth, e.g. http://localhost:4502/content.2.json
If you want to have XML you can just add the extenstion .xml to your path, though there it will just return the properties of the specified page and not the complete hierarchy as with JSON.
If you want get data through all hierarchy use 'infinity' selector and 'json' extension.
for example
http://localhost:4502/content/geometrixx/en/toolbar.infinity.json
Out of the box you can use the parent-folder-of-your-nodes.N.json notation as shown above.
If you need a specific format with just those properties you can write a script or servlet and mount it on a specific selector so that parent-folder-of-your-nodes.your-selector.json returns your custom format.
The http://sling.apache.org/documentation/the-sling-engine/servlets.html documentation should help with that, and there are numerous examples of such Sling servlets and scripts in the Apache Sling source code, for example under http://svn.apache.org/repos/asf/sling/trunk/launchpad/
Hello I'm in a bit of a jam here.
I'm trying to activate json calbacks (jsonp) on Alfresco 4.0.b following these directives.
http://wiki.alfresco.com/wiki/Web_Scripts#JSON_Callbacks
If I understand correctly for me to activate this feature for webscripts I need to modify this file /Alfresco/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/web-scripts-application-context.xml and add a property
<property name="allowCallbacks"><value>true</value></property>
to any bean definition I want json callbacks on.
Now from what I read everywhere you should never ever modify files inside alfresco.war or share.war. So here is my question:
How would I go about modifying this file outside of the alfresco war?
I tried copying the file to /Alfresco/tomcat/shared/classes/alfresco/web-scripts-application-context.xml and adding the propertie to the webscripts.container bean and the webscripts.authenticator.basic bean but both my script and the basic authentication script are not returning my results wrappped in my my_function when I use alf_callback=my_function
Any help would be greatly appreciated.
Thanks
Just placing a customized copy in shared/classes/alfresco does not work as beans still resolve from alfresco/WEB-INFO/classes/alfresco.
Try putting your customizations in shared/classes/alfresco/extension/whatever-context.xml.
The order of the imports is defined in alfresco/WEB-INF/classes/alfresco/application-context.xml - the last definition overrides and "wins".