How to deploy Tanstack Start to Cloudflare Workers

TanStack Start is currently in beta - this blog post works, as of 20/4/2025. I will aim to periodically return to this blog post and update it, if any braking changes have been released

Why Workers instead of Pages?

The Tanstack Start hosting page currently has a section dedicated to deploying on Cloudflare Pages. That said, I wouldn't recommend relying on Cloudflare Pages going forward; while Cloudflare Pages and Workers will be merging in the future, Cloudflare themselves have acknowledged that Workers are receiving the updates going forward.

Fortunately, you can host static assets and full-stack applications easily on Cloudflare Workers!

How do you deploy Tanstack Start to Cloudflare Workers?

Downloading the project files

First, start with the example project that is mentioned on the Tanstack Start website. You can access this via these bash commands:

npx gitpick TanStack/router/tree/main/examples/react/start-basic start-basic
cd start-basic
npm install
npm run dev

Updating app.config.ts

First, install unenv to the project, and then update your app.config.ts file to reflect the following:

import { defineConfig } from '@tanstack/react-start/config'
import tsConfigPaths from 'vite-tsconfig-paths'
import { cloudflare } from 'unenv'

export default defineConfig({
  tsr: {
    appDirectory: 'src',
  },
  server: {
    preset: 'cloudflare-module',
    unenv: cloudflare,
  },
  vite: {
    plugins: [
      tsConfigPaths({
        projects: ['./tsconfig.json'],
      }),
    ],
  },
})

Then update wrangler.jsonc to reflect this:

{
  "$schema": "node_modules/wrangler/config-schema.json",
  "compatibility_flags": ["nodejs_compat"],
  "compatibility_date": "2025-04-12",
  "main": ".output/server/index.mjs",
  "assets": {
    "directory": "./.output/public/",
    "binding": "ASSETS"
  },
}

Add a name field to this file, to set the name you want your deployed version to have.

Then build your project, with npm run build (as defined in your package.json file)

You should then see a prompt at the end of the build process, which includes the command you need to run to deploy to Cloudflare Workers:

npx wrangler --cwd .output/ deploy

You can also run wrangler deploy instead

And just like that, you have a deployed version of the Tanstack Start starter project!

The landing page of the Tanstack Start example project

(N.B. the starter project also has an example where it's calling API Routes - for these to work, you'll need to update the DEPLOY_URL in users.tsx, with the root URL of your deployed website)

Subscribe to Charles Williamson

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe