Repository navigation
fix(build): Make CJS re-exports visible to Node ESM imports - #25599
nicohrubec merged 2 commits into
Conversation
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
size-limit report 📦Compared: 41066b8 (PR test merge using develop at 6df508e) Against: 6df508e (develop) · base run #63271 ✅ Baseline matches: this diff contains only this PR's changes.
|
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3768aa9. Configure here.
|
@nicohrubec Is there any plan to backport this to the We're on Thanks🙇♂️ |
…port-condition-is-a-bare-cjs-path-with
|
@dayongkr yes! we'll merge this shortly and then backport to v10 so it should go out with the next v10 release :) |
Optional E2E testsSome optional checks were not successful. They do not block the merge. 2 not successful, 62 successful. See the run.
Successful checks
|
|
Thanks a lot!! |

When plain Node ESM code imports
@sentry/nextjs, Node loads the CJS build, because thenodeexport condition points to it. Namespace imports then miss about 180 exports (captureException,setUser, …), which are silentlyundefined.Rollup writes
export *in CJS as a loop with an arrow function, but Node only recognizes that loop with afunctioncallback. So Node can't see the@sentry/nodere-exports. Fixed by turning off arrow functions in Rollup's generated helpers.Splitting the
nodecondition is not needed for this fix. It is planned for later: #25598require()and default imports work as before@sentry/remix, which pinsnodeto CJS tooA unit test checks that Node sees the
@sentry/nodere-export.Fixes #22791