Skip to content

v12: Ditch CJS build #26671

Open
Open

Description

@isaacs

A common user request is to provide a default export from our SDKs: import Sentry from '@sentry/somesdk' rather than import * as Sentry from '@sentry/somesdk'.

However, this is quite annoying to do, for the fact that we build for both CJS and ESM, using the same types definitions, as typescript represents the default export quite differently between CJS and ESM. (For good reason; they're semantically different in very subtle ways that are impossible to represent 100% faithfully, even if these only become an issue in certain edge cases.)

Option 1: build types twice

This is definitely a possibility, and not terrible. It does increase our build times a tiny bit, but many projects do hybrid builds this way, and it's typically not that bad. It'll increase the download size of our packages by a modest amount, but the run-time cost stays what it is today.

As this is less good than Option 2 below, it's a known-mediocre fallback (maybe still better than "leave it, no change") if we run into problems.

Option 2: Ditch CJS

This has a ton of benefits. Faster CI (because we can cut out entire dimensions of several build/test matrices), smaller download size, etc. And, we can do it with only a very modest platform support coverage hit, because new Node versions all support require(esm).

The only hazard (apart from version support) is that if anything in the runtime dependency chain uses top-level await, it blows up.

Done when...

  • Survey node versions that support require(esm) to confirm we have the appetite to restrict our supported node versions to that list, and then do so. (Adjust CI matrices, engines fields, docs, etc.)
  • Ensure that none of our runtime dependencies use top-level await. This is probably fine, mostly the only runtime deps we have outside of this repo are either optional peer-deps that the user provides, @sentry/conventions, and @opentelemetry/api. But we should check, and have an integration test that'll fail if this changes. (Currently it seems safe.)
  • Update our build and deployment mechanisms to no longer build CJS.

Activity

  1. added this to the 12.0.0 milestone on Nov 19, 2026
  2. linear-code commented on Nov 19, 2026

    @linear-code
  3. isaacs commented on Nov 20, 2026

    @isaacs
    MemberAuthor

    Possibly related, but while we're considering options to shorten build times, we might also consider moving to erasableSyntaxOnly: true tsconfig, and stripping types rather than fully transpiling, so that our code doesn't need sourcemaps, or can even just shipping TS source directly with no build step, since it's almost the same Node version range for require(esm) and require(erasable-syntax-ts).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions