microsoft / microsoft/AdaptiveCards
[Feature Request] Distribute ESM alongside CJS, add "modules" entry.
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2k
- Forks
- 595
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 1
Description
Problem Statement
The adaptivecards package can't load in node. Try creating a test package with this dependency, run node, run require('adaptivecards'). The CJS you distribute can not import the ESM-only peer dependency "swiper". This causes numerous downstream consequences:
- You can never server render.
- You can't unit test it in an ESM-only jest environment.
- You get no tree-shaking from the bundler.
- Internal projects to speed up inner loops are blocked and must work around this package.
There's an existing issue: https://github.com/microsoft/AdaptiveCards/issues/6765. Hasn't been touched in a year and change.
We tried using this in a major M365 project, and ran into major blockers. Please address this with high priority.
Proposed solution
Like most browser packages in npm, you should be distributing ESM and pointing to your entry with the module key in your package.json. This prevents the scenario where your library can't load ESM dependencies. Even better, use an exports map as well which has priority over the legacy ways of declaring entries.
"exports": {
".": {
"types": "./path/to/any/index.d.ts",
"require": "./path/to/cjs/index.js",
"import": "./path/to/esm/index.js"
}
}
Alternatives or Workarounds
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure in a test package with Node and require('adaptivecards'), then inspect the package.json entry configuration. Review issue #6765 for prior context. Done means the package distributes usable CJS and ESM entries, including the proposed module or exports configuration, and the reported loading scenarios work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100