Skip to content

fix(nextjs): Expose common server APIs to Node ESM imports - #25378

Closed
adityareddy-dev wants to merge 1 commit into
getsentry:developfrom
adityareddy-dev:fix/nextjs-common-esm-exports-ef446
Closed

adityareddy-dev wants to merge 1 commit into
getsentry:developfrom
adityareddy-dev:fix/nextjs-common-esm-exports-ef446

Conversation

@adityareddy-dev

@adityareddy-dev adityareddy-dev commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Plain Node ESM imports resolve to the CJS server entry, where the star re-export from @sentry/node hides these eight APIs from static export detection. Explicitly re-export the reported APIs using the same pattern as pinoIntegration and vercelAIIntegration.

Keeps the Node export condition on CJS, as discussed in the issue. This covers the eight missing APIs listed in the report, rather than asserting parity for every export in the SDK.

Adds static export checks and a plain Node child-process test for named imports, namespace imports and equality with require().

Validated with yarn build:dev:filter @sentry/nextjs, then yarn test --coverage.enabled=false and yarn lint in packages/nextjs (1,228 tests passed, one expected failure). Also ran Oxfmt on both changed files and git diff --check. These local checks ran on Node 26.11.1 with Yarn 1.22.22, rather than the repo's pinned Node 24.21.0. Upstream build/test CI still needs maintainer authorization.

Refs #22791

  • Added regression tests.
  • Ensure code lints and the test suite passes (yarn lint) & (yarn test).
  • Linked the related issue.

@github-actions github-actions Bot added the external PR from an external contributor label Oct 15, 2026
@adityareddy-dev
adityareddy-dev marked this pull request as ready for review October 15, 2026 06:23
@adityareddy-dev
adityareddy-dev requested a review from a team as a code owner October 15, 2026 06:23
@adityareddy-dev
adityareddy-dev requested review from chargome and s1gr1d and removed request for a team October 15, 2026 06:24
@adityareddy-dev
adityareddy-dev marked this pull request as draft October 15, 2026 20:39
@adityareddy-dev
adityareddy-dev marked this pull request as ready for review October 15, 2026 20:41
@github-actions

Copy link
Copy Markdown
Contributor

👋 @chargome, @s1gr1d — Please review this PR when you get a chance!

s1gr1d added a commit that referenced this pull request Oct 21, 2026
When plain Node ESM code imports `@sentry/nextjs`, Node loads the CJS build, because the `node` export condition points to it. Namespace imports then miss about 180 exports (`captureException`, `setUser`, …), which are silently `undefined`.

Rollup writes `export *` in CJS as a loop with an arrow function, but Node only recognizes that loop with a `function` callback. So Node can't see the `@sentry/node` re-exports. Fixed by turning off arrow functions in Rollup's generated helpers.

- Only that loop changes, and only in CJS output. ESM output and CDN bundles are unchanged, so size-limit is not affected.
- Also fixes `@sentry/remix`, which pins `node` to CJS too.
- On Node 20, 22 and 24, namespace imports now match `require()`. Bun and Deno were not affected.
- Splitting the `node` condition is not needed for this fix and is still blocked (see #23628).
- Supersedes #25378, which re-exports only 8 of the missing names.

A unit test checks that Node sees the `@sentry/node` re-export.

Fixes #22791
@s1gr1d

s1gr1d commented Oct 21, 2026

Copy link
Copy Markdown
Member

Thanks for digging into this! We're going with a different fix in #25599, so I'm closing this one.

The explicit re-exports fix the 8 names from the report, but it still misses a lot of other exports.

We'll still split the node export condition later: #25598

@s1gr1d s1gr1d closed this Oct 21, 2026
nicohrubec pushed a commit that referenced this pull request Oct 23, 2026
When plain Node ESM code imports `@sentry/nextjs`, Node loads the CJS
build, because the `node` export condition points to it. Namespace
imports then miss about 180 exports (`captureException`, `setUser`, …),
which are silently `undefined`.

Rollup writes `export *` in CJS as a loop with an arrow function, but
Node only recognizes that loop with a `function` callback. So Node can't
see the `@sentry/node` re-exports. Fixed by turning off arrow functions
in Rollup's generated helpers.

```js
// before
Object.keys(node).forEach(k => { if (k !== 'default' && ...) exports[k] = node[k]; });

// after
Object.keys(browser).forEach(function (k) { /* ... */ }
```

Splitting the `node` condition is not needed for this fix. It is planned
for later: #25598

- Not breaking: this only makes hidden exports visible. `require()` and
default imports work as before
- Only that loop changes, and only in CJS output. ESM output and CDN
bundles are unchanged (same bundle-size)
- Also fixes `@sentry/remix`, which pins `node` to CJS too
- Supersedes #25378, which re-exports only 8 of the missing names

A unit test checks that Node sees the `@sentry/node` re-export.

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

Labels

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants