fix(tanstackstart-react): Add workerd and worker export conditions#19461
fix(tanstackstart-react): Add workerd and worker export conditions#19461smorimoto wants to merge 1 commit intogetsentry:developfrom
Conversation
773d0a1 to
e23013e
Compare
0ccd2f9 to
801e41a
Compare
|
Hey @smorimoto thanks for your PR and help to improve things going forward. I was looking over a PR. Do you have any examples on how this should look like in a production code? How is In general I'm not quite sure just yet where Cloudflare specifics of SDKs should land. If you want to make it possible to get basic Cloudflare support you can have the following import { withSentry } from '@sentry/cloudflare';
import handler, { createServerEntry } from '@tanstack/react-start/server-entry';
const requestHandler = withSentry(() => ({
dsn: '<YOUR_DSN>',
tracesSampleRate: 1,
}), {
async fetch(request: Request) {
return handler.fetch(request);
},
});
export default createServerEntry(requestHandler);And have this file as entrypoint in your |
|
Thanks for the review and the suggestion, @JPeer264! Regarding the It's also worth noting that this PR follows the same pattern already established by
So this approach keeps things consistent across the Sentry SDK ecosystem rather than introducing a different pattern for TanStack Start specifically. Happy to discuss further if you have any concerns! |
|
I'm totally not against adding the I was just unsure how you would use the Cloudflare export as I haven't seen an E2E test or any example in the PR description. Would you use If there are example we can add E2E tests for it, which is up to you if you add them or we add them for you in this PR.
About that. Did you enable If that is correct, we could reduce the PR to only add the new Cloudflare exports. |
Add `workerd` and `worker` export conditions to the `.` entry in package.json, pointing to `index.server.js`. This prevents the Cloudflare Vite plugin's resolve conditions (`workerd`, `worker`, `module`, `browser`) from falling through to the `browser` condition, which would resolve to `index.client.js` and trigger TanStack Start's import-protection plugin rejecting `*.client.*` files in the server environment. Users deploying to Cloudflare Workers will need `nodejs_compat` enabled in their wrangler configuration. A dedicated Cloudflare entrypoint (without `@sentry/node` dependency) will be addressed in a follow-up PR.
d92f1dc to
5ee7b1f
Compare
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.
|
Thanks for the feedback, @JPeer264! You raise a good point about This resolves the build-time issue: without these conditions, the For runtime, users would need A dedicated Cloudflare entrypoint (without |
Problem
When deploying a TanStack Start application to Cloudflare Workers, importing
@sentry/tanstackstart-reactcauses a build failure.The
@cloudflare/vite-pluginconfigures resolve conditions as["workerd", "worker", "module", "browser"]for the SSR environment. Since this package only definesbrowserandnodeconditions, the resolver falls through tobrowser, which points toindex.client.js. TanStack Start's import-protection plugin denies files matching**/*.client.*in the server environment, causing the build to fail.Related: TanStack/router#6688
Solution
Add
workerdandworkerexport conditions to the.entry inpackage.json, pointing toindex.server.js(the same target as thenodecondition). This ensures that bundlers targeting Workers runtimes resolve to the server entry rather than falling through to thebrowsercondition.Users deploying to Cloudflare Workers will need
nodejs_compatenabled in their wrangler configuration for@sentry/nodeto function correctly at runtime.A dedicated Cloudflare entrypoint (without
@sentry/nodedependency) will be addressed in a follow-up PR.Changed files
packages/tanstackstart-react/package.jsonworkerdandworkerexport conditions pointing toindex.server.js