From e772c4bf0240d1948e3d3db5ad803ef521853212 Mon Sep 17 00:00:00 2001 From: isaacs Date: Sat, 5 Dec 2026 14:26:09 -0800 Subject: [PATCH] fix(remix): Resolve the Cloudflare entry in Workers Cloudflare bundlers set the `workerd`, `worker` and `browser` conditions, and the first matching key wins. The root export of `@sentry/remix` listed `browser` before `worker`, so a bare `@sentry/remix` import in Worker code resolved to the client build. A `workerd` key now comes first and resolves the Cloudflare entry, as #24866 did for `@sentry/react-router`. Client bundles never set `workerd`, so nothing else changes. The Cloudflare entry now also exports `captureRemixServerException`. It was the one name the client build exported that the Cloudflare entry did not, so an app importing it in Worker code would fail to build after this change. Tests resolve a bare `@sentry/remix` with Node's resolver and the conditions Cloudflare sets, and check that the Cloudflare entry exports every name the client entry does. Co-Authored-By: Claude Opus 5.5 --- packages/remix/package.json | 5 +++ packages/remix/src/cloudflare/index.ts | 1 + .../remix/test/cloudflare-exports.test.ts | 39 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 packages/remix/test/cloudflare-exports.test.ts diff --git a/packages/remix/package.json b/packages/remix/package.json index 4d4d4fed7f73..47de377db965 100644 --- a/packages/remix/package.json +++ b/packages/remix/package.json @@ -25,6 +25,11 @@ "./package.json": "./package.json", ".": { "types": "./build/types/index.types.d.ts", + "workerd": { + "import": "./build/esm/cloudflare/index.js", + "require": "./build/cjs/cloudflare/index.js", + "default": "./build/esm/cloudflare/index.js" + }, "browser": { "import": "./build/esm/index.client.js", "require": "./build/cjs/index.client.js", diff --git a/packages/remix/src/cloudflare/index.ts b/packages/remix/src/cloudflare/index.ts index a7fa63ada474..02f08a89b032 100644 --- a/packages/remix/src/cloudflare/index.ts +++ b/packages/remix/src/cloudflare/index.ts @@ -15,6 +15,7 @@ export { browserTracingIntegration } from '../client'; export { ErrorBoundary } from '@sentry/react'; export { makeWrappedCreateRequestHandler, sentryHandleError }; export { generateSentryServerTimingHeader } from '../server/serverTimingTracePropagation'; +export { captureRemixServerException } from '../server/errors'; /** * Instruments a Remix build to capture errors and performance data. diff --git a/packages/remix/test/cloudflare-exports.test.ts b/packages/remix/test/cloudflare-exports.test.ts new file mode 100644 index 000000000000..f765c8749843 --- /dev/null +++ b/packages/remix/test/cloudflare-exports.test.ts @@ -0,0 +1,39 @@ +import { execFileSync } from 'node:child_process'; +import * as path from 'node:path'; +import { describe, expect, it } from 'vitest'; + +import * as cloudflare from '../src/cloudflare'; +import * as client from '../src/index.client'; + +const packageRoot = path.resolve(__dirname, '..'); + +function resolveRoot(conditions: string[]): string { + return execFileSync( + process.execPath, + [ + ...conditions.map(condition => `--conditions=${condition}`), + '--input-type=module', + '-e', + "console.log(import.meta.resolve('@sentry/remix'))", + ], + { cwd: packageRoot, encoding: 'utf8' }, + ).trim(); +} + +// Cloudflare resolves a bare `@sentry/remix` to the `workerd` entry, where +// it used to get the client build. A name only the client exports would +// break the build of an app that imports it in Worker code. +describe('Cloudflare entry', () => { + it('is what a bare import resolves to with the conditions Cloudflare bundlers set', () => { + expect(resolveRoot(['workerd', 'worker', 'browser'])).toMatch(/\/build\/esm\/cloudflare\/index\.js$/); + }); + + it('is not what a browser bundle resolves to', () => { + expect(resolveRoot(['browser'])).toMatch(/\/build\/esm\/index\.client\.js$/); + }); + + it('exports every name the client entry exports', () => { + const missing = Object.keys(client).filter(name => !(name in cloudflare)); + expect(missing).toEqual([]); + }); +});