-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hack to fix : "Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry'" #5407
Comments
I found the same issue when I import 2 custom elements in a page. Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': this name has already been used with this registry |
Did anyone fix this bug? |
https://www.npmjs.com/package/@lrnwebcomponents/deduping-fix we've been using this in our demo pages to get around this issue when it comes to mono-repo / lerna / yarn based development of polymer w/ polymer serve |
…2.8.0", Had to imcrement typescript version to get jasmine tests to run. preinstall.sh and fixNestings.sh are a solution to a polymer lib issue from here: Polymer/polymer#5407 Note that web component imports are commented out in polyfills.ts. In tsconfig.json, esModuleInterop is to fix "export 'process' was not found issue
I am getting the same issue using Any updates on that topic ? |
https://github.com/elmsln/wcfactory bakes in some pre and post install hook hacks in order to avoid this issue. I haven't seen any "do it this way" guidance that doesn't hamper workflow. you can see the solution we're using in our instance stamped from the tooling -- I'd happily switch off this if there was a better solution but I have yet to run into it. Run these scripts pre and post install, always do installs from the root of the monorepo. I update package.json's manually per element, then run yarn install from the root. Weakness of this approach:
|
Thanks for the sharing. I will definitely take a look at it. My project is private and can't be published on NPM for the moment. Therefore, I can't use the Enterprise NPM offer. I actually engaged myself to move to Lerna and a bootstrap.sh script just for the purpose of downloading the packages from NPM and my git repositories. I added a monorepo to gather all the packages that are part of my specific project and bootstrap it. The bootstrap copies all the node_modules at the root and creates the symbolic links in each packages. Thus, I can now develop easily in the packages that are dependent on each others. As a result, the Now I still need to resolve the publishing part (mainly because I want to publish to my git repositories and not to NPM). A bit of work I guess... |
could always just not publish. wcf sets things in motion for npm publishing but isn't required. |
Is removing the nesting polymer modules is the right solution for this problem? |
@msbasanth I had someone report this yesterday; maybe try running the postinstall manually after it's finished and see if that helps. I think it might be bc the yarn script running all in 1 swoop to install is putting a lock on the node modules directory (guess here) |
We have moved away from dynamic in-app deduping and as much as possible we use only sandard npm tools such as npm dedupe.
The general description of our approach is as follows: Clean up any previous npm dedupe related problems by removing node_modules. In your dependency projects run npm link. Ensure all links are in the root node_modules directory. Use npm dedupe to remove any duplications. More detail on the steps is like so :
now serve ! It should run nicely with nothing deduped at run time, all statically deduped on disk. We put the code snippets into their own moveLinks.sh and relink.sh scripts and call them from our own installation script which looks like so :
|
Thanks @flatmax for the detailed explanation. I will give a try with this approach. Thanks alot |
@btopro Yes, I could see it is script running when tried independently. yarn documentation says "The dedupe command isn’t necessary. yarn install will already dedupe.". So if we have a yarn workspace we need these scripts? Two approaches I tried,
Is it like we cannot separately bundle (rollup) with Polymer/LitElement elements at all? Or do we have things to take care when we bundle a PolymerElement using rollup? When I tried postinstall.sh is not helping with bundled elements. I could see rollup is used per element in https://github.com/elmsln/lrnwebcomponents. Is separately bundled UI WebComponents expected to work fine after running postinstall.sh? Am I doing wrong with my rollup config?
|
Using es-dev-server works fine now ! I have a script that will install the node_modules in every directory and will move them up in the root directory. Then it installs the node modules of the root directory. I hade this issue few times. I resolve this by:
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Quite often when developing polymer elements and more complex polymer apps, the browser reports :
Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry'"
It is caused by polymer modules which are nested in node_modules inside the top level node_modules directory.
EDIT: The following comments are now out of date ... see new approaches in the comment from December 20th 2019 below. There is an in-app dynamic solution and a static out of app solution.
Our workaround removes all nestings of polymer elements ...
In package.json, execute a preinstall script :
We find we have to do a scriptless npm install twice to make all elements install with bugs and then do the nested polymer element removal ...
The file preinstall.sh :
Then the file which removes nestings, fixNestings.sh :
Again, we don't like this approach, any work arounds ?
The text was updated successfully, but these errors were encountered: