Add Cloudflare Workers entrypoint and fix workerd/worker export conditions for tanstackstart-react#19461
Open
smorimoto wants to merge 3 commits intogetsentry:developfrom
Open
Conversation
On Cloudflare Workers the "browser" exports condition is matched, resolving the package entry to index.client.js. TanStack Start's import-protection plugin denies files matching **/*.client.* in the server environment, causing the build to fail. Add "workerd" and "worker" conditions before "browser" so that bundlers targeting Cloudflare Workers (e.g. @cloudflare/vite-plugin) resolve to index.server.js instead, avoiding the false positive. This follows the same pattern already used by @sentry/nextjs, @sentry/sveltekit, and @sentry/remix.
773d0a1 to
e23013e
Compare
The workerd/worker export conditions were pointing to the Node.js server entry which depends on @sentry/node and fails in Workers runtimes. This adds a dedicated cloudflare entrypoint (following the same pattern as remix and react-router packages) that re-exports framework utilities from @sentry/core instead, making the SDK compatible with Cloudflare Workers. Server module imports are also changed from @sentry/node to @sentry/core since all used APIs are available in both.
…ypoint Verify that the cloudflare entrypoint exports server implementations (not client no-op stubs) and passthrough ErrorBoundary/withErrorBoundary.
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.
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.
Problem
When deploying a TanStack Start application to Cloudflare Workers, importing
@sentry/tanstackstart-reactcauses two issues:Build failure: The
@cloudflare/vite-pluginconfigures resolve conditions as["workerd", "worker", "module", "browser"]for the SSR environment. Since this package only definedbrowserandnodeconditions, the resolver fell through tobrowser, which points toindex.client.js. TanStack Start's import-protection plugin denies files matching**/*.client.*in the server environment, causing a build failure.Runtime incompatibility: Even after adding
workerd/workerconditions (commit 773d0a1), they pointed toindex.server.jswhich re-exports@sentry/node. Since@sentry/nodedepends on Node.js APIs not available in Cloudflare Workers, this causes runtime errors.Related: TanStack/router#6688
Solution
Add a dedicated
src/cloudflare/index.tsentrypoint that provides Worker-compatible server utilities without depending on@sentry/node. This follows the same pattern used by@sentry/remixand@sentry/react-router(packages/remix/src/cloudflare/index.ts,packages/react-router/src/cloudflare/index.ts).Point
workerd/workerexport conditions to the cloudflare entrypoint instead ofindex.server.js, so bundlers targeting Workers runtimes automatically get the correct, Node-free build.Change server module imports from
@sentry/nodeto@sentry/coreinmiddleware.ts,wrapFetchWithSentry.ts, andutils.ts. All used APIs (startSpanManual,getActiveSpan,withActiveSpan,startSpan,SEMANTIC_ATTRIBUTE_SENTRY_OP,SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN) are available in@sentry/core. This has no effect on Node.js behavior since@sentry/nodere-exports@sentry/core, but allows the cloudflare entrypoint to safely import these server modules.Add
./cloudflaresubpath export for explicit imports (import { ... } from '@sentry/tanstackstart-react/cloudflare').What the cloudflare entrypoint exports
@sentry/react+ client init)wrapFetchWithSentry,wrapMiddlewaresWithSentry,sentryGlobalRequestMiddleware,sentryGlobalFunctionMiddlewareErrorBoundary/withErrorBoundaryWhat it does NOT export
@sentry/nodere-exports (not compatible with Workers)init(Node.js-dependent; use@sentry/cloudflarefor SDK initialization in Workers)Changed files
packages/tanstackstart-react/src/server/middleware.ts@sentry/coreinstead of@sentry/nodepackages/tanstackstart-react/src/server/wrapFetchWithSentry.ts@sentry/coreinstead of@sentry/nodepackages/tanstackstart-react/src/server/utils.ts@sentry/coreinstead of@sentry/nodepackages/tanstackstart-react/src/cloudflare/index.tspackages/tanstackstart-react/rollup.npm.config.mjspackages/tanstackstart-react/package.json./cloudflaresubpath, updatecircularDepCheckVerification
rollup -c rollup.npm.config.mjsbuild/esm/cloudflare/index.jsandbuild/cjs/cloudflare/index.jsare generated@sentry/node