-
Notifications
You must be signed in to change notification settings - Fork 24
ADR: CommonJS and ESM decision #323
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
Merged
+92
−0
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4953ec2
Create isomorphism-support init doc
kjugi 0f61c7a
update extension for file
kjugi 0e7a30f
Add Link to issue
kjugi a2f32cd
Add another issue to the list
kjugi aecf6f7
Update isomorphism-support.md
kjugi cb80fb5
Update isomorphism-support.md
kjugi bd86190
Update docs/adr/isomorphism-support.md
kjugi 81b58a8
Update docs/adr/isomorphism-support.md
kjugi fd24452
Update docs/adr/isomorphism-support.md
kjugi 1b35a67
Update docs/adr/isomorphism-support.md
kjugi ce20076
Apply suggestions from code review
kjugi f441533
Update isomorphism-support.md
kjugi 7392932
Update docs/adr/isomorphism-support.md
kjugi e4fee4e
Rename isomorphism-support.md to esm-support.md
kjugi db61d94
Update esm-support.md
kjugi a9ea109
Apply suggestion from @wesleytodd
ctcpip 0453296
✨ update ESM ADR for accuracy
ctcpip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # ADR: ESM exports | ||
|
|
||
| ## Status | ||
|
|
||
| Accepted | ||
|
|
||
| ## Submitters | ||
|
|
||
| - @kjugi | ||
| - @wesleytodd | ||
| - @ctcpip | ||
|
|
||
| ## Decision Owners | ||
|
|
||
| - @expressjs/express-tc | ||
|
|
||
| ## Context | ||
|
|
||
| The document's objective is to gather all notable comments and thoughts in one place and track potential changes in this topic. We have noticed that it is repeated frequently in many issues from the community and we need to take action. | ||
|
|
||
| We have acknowledged the need and discussion around it touched on multiple scenarios. Including: | ||
|
|
||
| - rethinking the process and exposing both options (ESM and CommonJS) for all libraries | ||
| - expose both options (ESM and CommonJS) for selected libraries | ||
| - maintaining status quo as the main target is on the server | ||
|
|
||
| **Why do we need this decision?** | ||
| We aimed to consolidate the Technical Committee's (TC) opinion on this topic. It is important to emphasize that Express is an HTTP framework specifically designed for Node.js. Additionally, some of our libraries are being utilized by the community in other environments. | ||
|
|
||
| **What problem does it solve or avoid?** | ||
| Ambiguity and uncertainty for the community, alongside clear guidance for repository maintainers and contributors. | ||
|
|
||
| **Are there any existing issues/discussions/pull requests related to this?** | ||
|
|
||
| - <https://github.com/pillarjs/router/issues/128> | ||
| - <https://github.com/expressjs/discussions/issues/297> | ||
| - <https://github.com/expressjs/express/discussions/6051> | ||
| - <https://github.com/jshttp/cookie/issues/211> | ||
|
|
||
| ## Decision | ||
|
|
||
| Holistically, as a project/team, we will not make a dedicated effort to export our libraries in the ESM format. | ||
|
|
||
| This applies to all [expressjs](https://github.com/expressjs), [pillarjs](https://github.com/pillarjs), or [jshttp](https://github.com/jshttp) packages. | ||
|
|
||
| **However, repo captains, as the primary maintainers of packages, retain autonomy and discretion of whether or not they choose to support ESM exports directly.** | ||
|
|
||
| ### What will be done? | ||
|
|
||
| Future issues and PRs regarding ESM exports may be closed with a link to this document. | ||
|
|
||
| ## Rationale | ||
|
|
||
| During the [working session](https://github.com/expressjs/discussions/issues/320), we had an in-depth discussion about this topic. | ||
|
|
||
| This decision is motivated by the lack of resources to maintain such an effort in the long term. It is also worth noting that Express was specifically designed to run with Node.js. | ||
|
|
||
| At present, our libraries function seamlessly in Node.js, supporting both CommonJS and ESM. Transitioning to support additional scenarios, such as direct ESM exports, would require significant changes to our CI systems and additional maintenance overhead. | ||
|
|
||
| While the JavaScript ecosystem has increasingly moved toward ESM due to its compatibility with browsers, enhanced tree-shaking capabilities (coming from bundler tools), and support for dynamic imports, there are still complexities and challenges associated with ESM. | ||
|
|
||
| Adopting ESM for our libraries would require a significant investment of time and resources to ensure proper implementation and long-term maintenance. While it is not impossible to achieve, it represents a considerable effort. Moreover, the majority of our users already utilize our libraries in their projects, relying on bundlers to handle the necessary transformations without issues. | ||
|
|
||
| - **Alternatives Considered:** | ||
| - Add ESM export to our libraries. CommonJS format is accepted by bundlers. | ||
| - **Why is this decision the best option?** | ||
| - Time and energy can be shifted to other topics. | ||
|
|
||
| ## Consequences | ||
|
|
||
| - **Positive Impact**: It does not require supporting another set of tools and major release. | ||
| - **Negative Impact**: | ||
| - No guarantee the packages work in browser environments. | ||
| - Potential community library fork (to make it ESM-friendly) might lack security updates over time | ||
| - OSS library authors that use our packages in ESM native libs might suffer from a lack of support | ||
| - **Mitigations**: Package maintainers may decide to expose both CJS and ESM | ||
|
|
||
| ## References | ||
|
|
||
| Support for commonjs imports in ESM code is available in the node. Described in docs: | ||
|
|
||
| - <https://nodejs.org/api/esm.html#interoperability-with-commonjs> | ||
|
|
||
| Support for ESM modules imports in commonjs is available in recent LTS Node.js versions. Docs: | ||
|
|
||
| - <https://nodejs.org/api/modules.html#loading-ecmascript-modules-using-require> | ||
|
|
||
| ## Changelog | ||
|
|
||
| Track changes or updates to this ADR over time. Include the date, author, and a brief description of each change. | ||
|
|
||
| - **[2025-01-15] - [2026-04-01]**: [@kjugi, @ctcpip, @wesleytodd] - initial doc | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.