microsoft / microsoft/AdaptiveCards

[Feature Request] Distribute ESM alongside CJS, add "modules" entry.

Open
#8,627 1 comment 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Request
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:

  1. You can never server render.
  2. You can't unit test it in an ESM-only jest environment.
  3. You get no tree-shaking from the bundler.
  4. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.