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

[feat] document on best practice of package.json for dual package (CJS+ESM) #53948

Closed
5 tasks done
loynoir opened this issue Apr 21, 2023 · 3 comments
Closed
5 tasks done
Labels
Duplicate An existing issue was already created

Comments

@loynoir
Copy link

loynoir commented Apr 21, 2023

Suggestion

🔍 Search Terms

List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.

  • dual package CJS + ESM
  • package.json best practice

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

I fork a typescript CJS repo to add ESM support.


sinclairzx81/typebox#400 (comment)

Do you have any reference links on best practice to support both ESM and CJS? I assume the cjs and esm submodule pathing is a common, but curious on best practice configuration of package.json. I had been meaning to support ESM, however probably as a minor semver, as internal directories have been changed.


I use below config, seems working, but not sure if it is best practice.

Therefore, request for a official document.

https://github.com/loynoir/typebox/blob/feat-esm/package.json#L13-L56

==> cjs/package.json <==
{"type":"commonjs"}

==> esm/package.json <==
{"type":"module"}

📃 Motivating Example

💻 Use Cases

@MartinJohns
Copy link
Contributor

Duplicate of #52593. You should mention your use case there, if it wasn't mentioned already (likely was).

@loynoir
Copy link
Author

loynoir commented Apr 21, 2023

The issue behind this feat is #53949

dts resolve to CJS entry dts instead of ESM entry dts

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Apr 21, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants