Skip to content
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

Correct exports of the module for better module loading compatibility with node.js #908

Open
trygve-lie opened this issue Aug 12, 2024 · 0 comments · May be fixed by #909
Open

Correct exports of the module for better module loading compatibility with node.js #908

trygve-lie opened this issue Aug 12, 2024 · 0 comments · May be fixed by #909
Labels
triage me I really want to be triaged. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@trygve-lie
Copy link

trygve-lie commented Aug 12, 2024

Is your feature request related to a problem? Please describe.

This module exports a UMD module in the main field and it provides an ESM version through the module field in package.json. Node.js supports mixing CJS and ESM modules these days but this setup does not go well with using this module in node.js.

The module field are only used by bundlers. Its not supported by node.js. So when trying to use this module with node.js without bundling it will try to load the file references in the main field which is a UMD file that node.js does not understand either.

Iow; how the ESM version is exposed in this module is wrong according to node.js.

My problem with this is that this breaks SSR of Lit web components (I am using this module in a Lit web component) and it also breaks SSR in Nuxt it seems like. Using this module with Lit SSR is possible if it only where exported correctly.

Describe the solution you'd like

Set package.json to type: module and export the ESM as recommended by node.js: https://nodejs.org/api/packages.html#dual-commonjses-module-packages

Basically add:

  "type": "module",
  "exports": {
    "import": "./dist/index.esm.js",
    "require": "./dist/index.umd.js"
  },

Describe alternatives you've considered

I don't think there is an alternative way of doing this.

@trygve-lie trygve-lie added triage me I really want to be triaged. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Aug 12, 2024
@trygve-lie trygve-lie linked a pull request Aug 12, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant