From 70db41c54296afe050f102ef91e5d7483a5d8f36 Mon Sep 17 00:00:00 2001 From: Jonghyeon Ko Date: Mon, 23 Nov 2026 02:20:36 +0900 Subject: [PATCH] Fix Sentry source map uploads for Cloudflare builds --- docs/cloudflare-workers-migration.md | 2 ++ public/.assetsignore | 1 + vite.config.ts | 39 +++++++++++++++++----------- 3 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 public/.assetsignore diff --git a/docs/cloudflare-workers-migration.md b/docs/cloudflare-workers-migration.md index 7b5decbab..f0872137d 100644 --- a/docs/cloudflare-workers-migration.md +++ b/docs/cloudflare-workers-migration.md @@ -47,6 +47,8 @@ Cloudflare Workers Builds is the production deployment owner. Its production tri The CI deploy command applies every committed migration and verifies the exact Builder schema before `wrangler deploy` can run. Preview builds use `wrangler versions upload` and must not receive the production database secret. +Set `SENTRY_AUTH_TOKEN` under **Settings → Build → Build variables and secrets** for the `tanstack-com` Worker. Builds on `main` use this token to upload browser and Worker source maps to `tanstack/tanstack-com`. Check the build log and the [Sentry Source Maps page](https://tanstack.sentry.io/settings/projects/tanstack-com/source-maps/) after the next production build. + Required environment: - `DATABASE_URL`: the production Postgres connection used to verify the Builder schema before the Worker is deployed. Run `pnpm run db:prepare-builder` once after a Builder schema change. diff --git a/public/.assetsignore b/public/.assetsignore new file mode 100644 index 000000000..c7de605bd --- /dev/null +++ b/public/.assetsignore @@ -0,0 +1 @@ +*.map diff --git a/vite.config.ts b/vite.config.ts index 541a0d08c..b31fdff2c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -29,11 +29,6 @@ import { workerIsolation } from './scripts/worker-isolation-vite' const isDev = process.env.NODE_ENV !== 'production' const shouldUseRedact = process.env.DISABLE_REDACT !== 'true' const localRedactPackageRoot = process.env.LOCAL_REDACT_PACKAGE_ROOT -const shouldUseSentryPlugin = - process.env.NODE_ENV === 'production' && - Boolean(process.env.SENTRY_AUTH_TOKEN) -const shouldBuildSourcemaps = - shouldUseSentryPlugin || process.env.BUILD_SOURCEMAPS === 'true' const SITE_URL = process.env.STAGING_SITE_URL || 'https://tanstack.com' const localDocsDevToken = isDev ? randomUUID() : '' @@ -217,6 +212,19 @@ function chatBuildId() { export default defineConfig(async ({ command, mode }) => { const localEnv = { ...loadEnv(mode, __dirname, ''), ...process.env } + const isProductionBuild = command === 'build' && mode === 'production' + const cloudflareBranch = process.env.WORKERS_CI_BRANCH + const sentryAuthToken = + isProductionBuild && (!cloudflareBranch || cloudflareBranch === 'main') + ? localEnv.SENTRY_AUTH_TOKEN + : undefined + const shouldBuildSourcemaps = + Boolean(sentryAuthToken) || localEnv.BUILD_SOURCEMAPS === 'true' + if (isProductionBuild && cloudflareBranch === 'main' && !sentryAuthToken) { + console.warn( + '[Sentry] Source map upload skipped. Set SENTRY_AUTH_TOKEN in Cloudflare Workers Builds.', + ) + } const useRemoteAi = Boolean(localEnv.CLOUDFLARE_API_TOKEN) const egress = command === 'serve' ? await startLocalMcpEgress() : undefined const config: UserConfig = { @@ -264,6 +272,9 @@ export default defineConfig(async ({ command, mode }) => { : undefined, }, environments: { + client: { + build: { sourcemap: shouldBuildSourcemaps ? 'hidden' : false }, + }, ssr: { optimizeDeps: { // Resolve SSR dependencies through Redact instead of a separate prebundle. @@ -520,16 +531,6 @@ export default defineConfig(async ({ command, mode }) => { viteReact(), chatIsolation(), workerIsolation(), - - ...(shouldUseSentryPlugin - ? [ - sentryTanstackStart({ - authToken: process.env.SENTRY_AUTH_TOKEN, - org: 'tanstack', - project: 'tanstack-com', - }), - ] - : []), contentCollections(), tailwindcss(), ...(process.env.ANALYZE @@ -541,6 +542,14 @@ export default defineConfig(async ({ command, mode }) => { }), ] : []), + ...(sentryAuthToken + ? sentryTanstackStart({ + authToken: sentryAuthToken, + org: 'tanstack', + project: 'tanstack-com', + autoInstrumentMiddleware: false, + }) + : []), ], } return config