Banno / polymer-webpack-loader

WebPack Loader for Polymer Web Components
MIT License
193 stars 48 forks source link

Polymer2 DomModule.prototype.modules is Empty #121

Open Marshal27 opened 3 years ago

Marshal27 commented 3 years ago

I have a business requirement to leverage lit NPM packages in a Polymer 2 application, we are purchasing an upgrade to Polymer 3 on the repo however, we have an immediate need to consume our lit npm packages in the current Polymer version.

I am attempting to leverage v2.0.3 in our current repo, have been successful in replicating the demo using ate-fns/format but unfortunately, as soon as I import my custom NPM package DomModule.prototype.modules is empty and I receive the following.

Uncaught DOMException: CustomElementRegistry.define: 'dom-module' has already been defined as a custom element dom-module.html:199

I apologize in advance for posting a support type item as an issue; this being the Polymer 2 version and the time-sensitive situation I am in, I was hoping someone here would be able to either point me in the right direction and or confirm that what I am attempting to accomplish may not be possible.

Thank you in advance for any help.

bryandcoulter commented 3 years ago

This is a bit outside of the loader but Uncaught DOMException: CustomElementRegistry.define: 'dom-module' has already been defined as a custom element dom-module.html:199 means your app is importing 2 different version of polymer. So when you hit the second version and the first has already been defined in the customElements registry it will deny the second from being added.

Marshal27 commented 3 years ago

Hi Bryan, I really appreciate you taking the time to respond so quickly on this.

I did take a look at the package-lock.json file of my NPM project and there are dependencies loading "@polymer/polymer": "^3.0.0"...

again I appreciate you taking the time to respond/point me in the right direction. The underlying dependencies are too large of a refactor to confirm if that is the issue definitively, but based on your response I suspect this to be the culprit.

bryandcoulter commented 3 years ago

If you are using polymer 2 and a dependency is using polymer 3 that would cause the issue you are seeing.

Marshal27 commented 3 years ago

Thanks again Bryan for your help.

I was able to confirm that by modifying the src in node_modules to remove all dependencies from the package class and return a hello world template from the render function of the class... the package was imported successfully and the template was rendered.

Sorry for tying you up on this, but truly appreciate your help pinpointing the root issue.

bryandcoulter commented 3 years ago

No worries, good luck!