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

Better ESM/CJS support #648

Closed
vladmoroz opened this issue Sep 27, 2024 · 2 comments · Fixed by #821
Closed

Better ESM/CJS support #648

vladmoroz opened this issue Sep 27, 2024 · 2 comments · Fixed by #821
Assignees
Labels
bug 🐛 Something doesn't work core Infrastructure work going on behind the scenes

Comments

@vladmoroz
Copy link
Contributor

vladmoroz commented Sep 27, 2024

Current issues

  • Defaults to CJS even for modern Node
    • node folder for CJS is misleading and not discoverable
    • View source action in VS Code goes to the (hard to read) CJS version
  • package.json doesn’t specify the type field
  • ESM code is missing extensions
    • ESM version can't be used without a bunlder
    • Makes it incompatible with moduleResolution: "Node" | "NodeNext"

Suggestions

My preferred implementation would be to do what we learned from doing the dual package in Radix Themes (see on unpkg):

  • type: "commonjs" in the root package.json
  • type: "module" in the esm folder package.json
  • exports field with require and import declarations
  • Explicit cjs and esm folders in the built package
    • Makes it easy for consumers to find the right version if they need to explicitly point their tooling to the ESM/CJS version
  • Extensions in source code
    • No build tooling would be needed to transform extensions
    • ESLint can enforce this and auto add them, VSC support is good too

publint can be a good way to check if all looks good:
https://publint.dev/@base_ui/[email protected]
https://publint.dev/@radix-ui/[email protected]

Some details on the possible implementations:
https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html

@github-actions github-actions bot added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 27, 2024
@vladmoroz vladmoroz added core Infrastructure work going on behind the scenes bug 🐛 Something doesn't work labels Sep 27, 2024
@atomiks atomiks assigned michaldudak and unassigned atomiks Sep 29, 2024
@michaldudak
Copy link
Member

Done in #821

Copy link

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@github-actions github-actions bot removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work core Infrastructure work going on behind the scenes
Projects
None yet
3 participants