Repository navigation
fix(nextjs): Expose common server APIs to Node ESM imports - #25378
Closed
adityareddy-dev wants to merge 1 commit into
Closed
adityareddy-dev wants to merge 1 commit into
adityareddy-dev wants to merge 1 commit into
Conversation
adityareddy-dev
marked this pull request as ready for review
October 15, 2026 06:23
adityareddy-dev
requested review from
chargome and
s1gr1d
and removed request for
a team
October 15, 2026 06:24
adityareddy-dev
marked this pull request as draft
October 15, 2026 20:39
adityareddy-dev
marked this pull request as ready for review
October 15, 2026 20:41
Contributor
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
Member
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Plain Node ESM imports resolve to the CJS server entry, where the star re-export from
@sentry/nodehides these eight APIs from static export detection. Explicitly re-export the reported APIs using the same pattern aspinoIntegrationandvercelAIIntegration.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, thenyarn test --coverage.enabled=falseandyarn lintinpackages/nextjs(1,228 tests passed, one expected failure). Also ran Oxfmt on both changed files andgit 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
yarn lint) & (yarn test).