{
  "id": 15363005,
  "title": "How to deploy TanStack Start to Cloudflare Workers with D1, R2 and better-auth",
  "url": "https://urgent.news/2026/10/18/how-to-deploy-tanstack-start-to-cloudflare-workers-with-d1-r2-and",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-18T06:30:41.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/hongwei_wang/how-to-deploy-tanstack-start-to-cloudflare-workers-with-d1-r2-and-better-auth-3hoc"
  },
  "original_language": "en",
  "account": "Deploying TanStack Start to Cloudflare Workers with D1, R2 and better-auth is straightforward with the right setup. The entire application resides within a single Worker, eliminating the need for connection strings or S3 keys. To begin, clone the free MIT-licensed starter tanstack-start-cloudflare-starter. Versions as of writing are:\n\n- @tanstack/react-start 1.168\n- @cloudflare/vite-plugin 1.40\n- wrangler 4.99\n- better-auth 1.6\n- drizzle-orm 0.45.1\n\nThe wrangler.jsonc file configures the Worker, specifying D1, R2, and a rate limiter. Key settings include:\n\n1. html_handling: drop-trailing-slash - This ensures prerendered pages match their canonical URLs.\n2. migrations_dir: drizzle - Drizzle Kit writes SQL migrations in the ./drizzle folder, which Wrangler applies without direct interaction with D1.\n3. Enable observability and set the migration directory to 'drizzle' for automatic SQL migrations.\n\nThe Vite configuration uses the Cloudflare plugin for SSR and TanStack Start for prerendering. It excludes .wrangler/ from Vite's watch list to prevent full page reloads when databases or uploads occur.\n\nKey snippets include the Vite configuration (trimmed for brevity):\n\n```typescript\nimport { cloudflare } from '@cloudflare/vite-plugin';\nimport { tanstackStart } from '@tanstack/react-start/plugin/vite';\nimport viteReact from '@vitejs/plugin-react';\nimport { defineConfig } from 'vite';\nimport { isPrivatePath } from './src/config/private-paths';\n\nexport default defineConfig({\nresolve: { tsconfigPaths: true },\nserver: {\nwatch: {\nignored: ['**/.wrangler/**'],\n},\n},\nplugins: [\ncloudflare({\nviteEnvironment: { name: 'ssr' },\n}),\ntanstackStart({\nprerender: {\nenabled: true,\ncrawlLinks: true,\nfilter: (page) => !page.path.includes('?') && !isPrivatePath(page.path),\n},\n}),\nviteReact(),\n],\n});\n```\n\nThis setup enables Cloudflare to run your server code in the same runtime as production, with local D1 and R2 storage. Remember to ignore .wrangler/ when using Vite's watch feature to avoid issues with database writes and uploads.",
  "summary": "TanStack Start runs well on Cloudflare Workers. The official guides get you to \"Hello world\" quickly. The trouble starts when you add a database, file uploads and auth, because each of those touches the Workers runtime in a slightly different way. This post walks through a setup I use in production: one Worker that serves prerendered marketing pages as static assets and everything else from…",
  "key_points": [
    "Clone tanstack-start-cloudflare-starter, version 1.168, 1.40, 4.99, 1.6, 0.45.1",
    "Configure wrangler.jsonc for D1, R2, rate limiter, migration directory",
    "Use Cloudflare plugin in Vite config for SSR and prerendering"
  ],
  "editors_take": "Consolidating the entire application within a single Worker removes the friction of managing external connection strings and keys, streamlining the deployment of full-stack TanStack Start applications.",
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}