Skip to content

TypeScript w/ esModuleInterop: import Sentry from "@sentry/{node|browser}" is not an error, but does not work. #3105

Open

Description

@krisdages

Relates to PR #3077

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:

Version:

5.29.0

Description

Sentry must be imported using import * as Sentry instead of import Sentry in order to work.
With the esModuleInterop compiler option enabled, TypeScript does not complain about import Sentry.
(With the option off, TS recognizes that the module does not have a default import and forbids import Sentry)

This appears to be because the Sentry index.js module declares __esModule: true but does not actually have a value for the default export:

 // import Sentry from "@sentry/node" - transpiled
 node_1 = tslib_1.__importDefault(node_1);

 //tslib
 __importDefault = function (mod) {
        return (mod && mod.__esModule) ? mod : { "default": mod };
    };

Can the library be updated so the default import works as TypeScript thinks it does?
This is only an issue when the esModuleInterop setting is on, but it's a pretty valuable setting and a dangerous mistake
for the developer.

// Either 
// vv - Can this be added?
exports.default = exports;

// Or
// vv - Can this be removed?  Though it would make the `import *` less efficient. 
Object.defineProperty(exports, "__esModule", { value: true });

Thanks!

Activity

  1. bodinsamuel commented on Dec 21, 2020

    @bodinsamuel

    +1 on this
    The typescript definition does not report an error but it's indeed broken

  2. killthekitten commented on Feb 25, 2021

    @killthekitten

    Same goes for @sentry/serverless. Search terms:

    Cannot read property 'GCPFunction' of undefined
    
  3. fosrias commented on May 25, 2021

    @fosrias

    @rbisol Why is this not a bug. It basically makes this library unusable when you are working in an environment requiring interop?

  4. lo1tuma commented on Jul 12, 2021

    @lo1tuma

    I’ve ran into this problem as well. Since we are using dependency injection we almost shipped a broken version of our app to production.

  5. florian-milky commented on Jul 22, 2021

    @florian-milky

    FWIW, if I remove this line from the commonJS module:
    Object.defineProperty(exports, "__esModule", { value: true });, it works as expected

  6. imsamurai commented on Oct 13, 2022

    @imsamurai

    any news?

  7. lforst commented on Oct 14, 2022

    @lforst
    Contributor

    @imsamurai is this still an issue with the newest version of the SDK? We updated how we bundle the SDK in version 7.x.x.

  8. incompletude commented on Dec 23, 2022

    @incompletude

    still a problem, no default export

  9. 58 remaining items

  10. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Oct 16, 2026
  11. 61465 commented on Oct 16, 2026

    @61465
    Contributor

    Thanks for the branch link @JPeer264 — checked it. The write-esm-types.mjs approach is sound, and the default-export guard is a solid safety net for cases where export * would silently drop the default.

    Two things I didn't find in a repo search:

    1. No public issue for the "different subexports" plan. If it's internal-only, this issue is the de-facto home. Happy to open a dedicated tracking issue if that's cleaner.

    2. Branch covers @sentry/browser + @sentry/node only. The repo has 49 packages (gh api repos/getsentry/sentry-javascript/contents/packages), so a full fix wants:

      • write-esm-types.mjs run as part of the build pipeline, not manually per-package
      • per-package exports maps updated with types.import → .d.mts, types.default → .d.ts
      • attw --from-npm --profile node16 regression check in CI so future type regressions get caught

    Current main ships v9 for CJS (per #15018) — attw now reports node16 (from CJS): OK, but node16 (from ESM): 🎭 Masquerading as CJS is still live on @sentry/browser@11.8.0 and @sentry/node. The fix is the types alignment you already prototyped.

    Happy to pick up the plumbing (build integration + CI attw matrix + all 49 packages in one atomic PR) with you as co-author, or sit back if you've already got the follow-up queued. Either works — let me know which you prefer.

  12. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 16, 2026
  13. JPeer264 commented on Oct 19, 2026

    @JPeer264
    Member

    @61465 I highly appreciate that you ask before you create a PR. However, It feels like I'm talking to a bot and I'd assume the PR would feel the same (sorry that I assumed a lot here). I think I'll take over the ticket here and check if we can land this after these years.

  14. self-assigned this
    on Oct 19, 2026
  15. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Oct 19, 2026
  16. 61465 commented on Oct 19, 2026

    @61465
    Contributor

    26. @61465 I highly appreciate that you ask before you create a PR. However, It feels like I'm talking to a bot and I'd assume the PR would feel the same (sorry that I assumed a lot here). I think I'll take over the ticket here and check if we can land this after these years.

    No worries at all, Jan Thanks for your time and looking into this.
    I actually just use AI to help format and structure my longer messages. Honestly, it's much better for maintainers to read a well organized text than to try and decipher my typos and spelling mistakes

    Since you are taking over the ticket, go for it. I'm right here if you need any help, testing, or a second pair of eyes on the PR. Cheers

  17. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 19, 2026
  18. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Oct 19, 2026
  19. added this to the 12.0.0 milestone on Nov 20, 2026
  20. JPeer264 commented on Nov 20, 2026

    @JPeer264
    Member

    FYI. We will implement this in v12 as this might break some setups. Even though this is technically a fix we still try to not break any users code in a minor, especially if this was in there for a while.

    There is no active timeline when we will start with v12 but I assume it is somewhere 2027 more towards mid or end of the year. In the meantime I’ll try to add something into the docs so it is also documented that default exports are not supported.

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

Metadata

Metadata

Assignees

Labels

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions