Polymer / polymer

Our original Web Component library.
https://polymer-library.polymer-project.org/
BSD 3-Clause "New" or "Revised" License
22.05k stars 2.02k forks source link

Polymer cannot be used with Skypack #5678

Open Legioth opened 3 years ago

Legioth commented 3 years ago

Polymer cannot be used reliably from the Skypack CDN. By extension, any application that uses third party web components based on Polymer cannot use the new Streaming Imports mode introduced in Snowpack 3.

A simple example works as long as there's either only an import for the main module (@polymer/polymer) or only specific module imports (e.g. @polymer/polymer/polymer-element.js). Mixing those two modes will lead to dom-module being defined twice - once inlined into the main bundle and once as a standalone file through the other import. Consistently using only one way of importing is possible in a limited application, but typically not when using third party components (such as almost anything from Vaadin).

Fixing this would probably need a proper exports map in package.json which would let Skypack known which modules might be loaded separately and should thus not be inlined into the main bundle. I'm making this assumption based on what I read in https://docs.skypack.dev/package-authors/package-checks#export-map - I haven't tested it in practice.

Improving compatibility between Polymer and Skypack / Snowpack is mostly important because new applications started using a more modern tech stack might still want to reuse existing web components implemented using Polymer. Without a fix, they would have to find replacement components that are compatible with their tech stack.

Live Demo

https://jsbin.com/jabapumota/edit?html,console

Steps to Reproduce

  1. Import @polymer/polymer from cdn.skypack.dev
  2. Import @polymer/polymer/polymer-element.js from cdn.skypack.dev

Expected Results

No exceptions

Actual Results

Error: Failed to execute 'define' on 'CustomElementRegistry': the name "dom-module" has already been used with this registry

Versions

matthewp commented 3 years ago

Hi, I work for Skypack and I can confirm that using an export map will allow the CDN to optimize the build when multiple entrypoints are expected. If this project is now inactive then another option is for you to contribute an export map to https://github.com/snowpackjs/DefinitelyExported and we can make sure it is used in the CDN.

stale[bot] commented 2 years ago

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.