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) #47661

Closed
loynoir opened this issue Apr 21, 2023 · 1 comment
Closed
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@loynoir
Copy link

loynoir commented Apr 21, 2023

What is the problem this feature will solve?

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.

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

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

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

What is the feature you are proposing to solve the problem?

Official document on best practice of package.json for dual package (CJS+ESM).

What alternatives have you considered?

No response

@loynoir loynoir added the feature request Issues that request new features to be added to Node.js. label Apr 21, 2023
@aduh95
Copy link
Contributor

aduh95 commented Apr 22, 2023

There's https://nodejs.org/api/packages.html#dual-commonjses-module-packages.

Closing for now, we can reopen if you think the docs is missing something (or don't hesitate to open a PR to improve the docs if you have suggestions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

No branches or pull requests

2 participants