From 3768aa95b644a4b3592fae289072b3662d9573b5 Mon Sep 17 00:00:00 2001 From: s1gr1d <32902192+s1gr1d@users.noreply.github.com> Date: Wed, 21 Oct 2026 10:41:57 +0200 Subject: [PATCH] fix(build): Make CJS re-exports visible to Node ESM imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- dev-packages/rollup-utils/npmHelpers.mjs | 2 ++ packages/nextjs/test/serverExports.test.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/dev-packages/rollup-utils/npmHelpers.mjs b/dev-packages/rollup-utils/npmHelpers.mjs index a113feb1aa75..7d1d7b794eef 100644 --- a/dev-packages/rollup-utils/npmHelpers.mjs +++ b/dev-packages/rollup-utils/npmHelpers.mjs @@ -108,6 +108,8 @@ export function makeBaseNPMConfig(options = {}) { // Allow wrappers or helper functions generated by rollup to use any ES2015 features generatedCode: { preset: 'es2015', + // With arrow functions, Node can't see `export *` exports when ESM code imports our CJS files. + arrowFunctions: false, }, // don't add `"use strict"` to the top of cjs files diff --git a/packages/nextjs/test/serverExports.test.ts b/packages/nextjs/test/serverExports.test.ts index 558c890e93b8..caeb99569498 100644 --- a/packages/nextjs/test/serverExports.test.ts +++ b/packages/nextjs/test/serverExports.test.ts @@ -35,3 +35,17 @@ describe('Node-only integrations are statically detectable exports from every ru }, ); }); + +/** + * Node loads this CJS file for ESM imports too, and must see that it re-exports everything from `@sentry/node`. + * + * Regression test for https://github.com/getsentry/sentry-javascript/issues/22791 + */ +describe('CJS server build re-exports are detectable by Node', () => { + it('detects the `@sentry/node` re-export', async () => { + await init(); + const { reexports } = parse(readFileSync(resolve(__dirname, '../build/cjs/index.server.js'), 'utf8')); + + expect(reexports).toContain('@sentry/node'); + }); +});