Skip to main content
Cloudflare Workers is a serverless platform that runs your code on Cloudflare’s global edge network. TanStack Start applications can be deployed to Cloudflare Workers with just a few configuration steps.

Prerequisites

  • A Cloudflare account (sign up here)
  • Node.js and pnpm (or npm/yarn) installed
  • A TanStack Start application

Installation

Install the required dependencies for Cloudflare Workers deployment:

Configuration

1. Update Vite Config

Add the Cloudflare plugin to your vite.config.ts file:
The cloudflare plugin must be placed before tanstackStart() in the plugins array.

2. Create Wrangler Configuration

Create a wrangler.jsonc file in your project root:

3. Update Package Scripts

Modify the scripts in your package.json:

Environment Variables

You can add environment variables to your wrangler.jsonc file:
For secrets, use the Wrangler CLI:

Accessing Cloudflare Bindings

You can access Cloudflare bindings (KV, D1, R2, etc.) in your server functions:

Type Generation

Generate TypeScript types for your Cloudflare bindings:
This creates a worker-configuration.d.ts file with type definitions for your environment.

Deployment

Authentication

First, authenticate with your Cloudflare account:
To check your current authentication status:

Deploy to Production

Deploy your application:
This will:
  1. Build your application with Vite
  2. Run TypeScript type checking
  3. Deploy to Cloudflare Workers
After deployment, Wrangler will provide a URL where your application is live.

Advanced Configuration

Custom Routes

Configure custom routes in wrangler.jsonc:

Workers KV

Add KV namespaces to your configuration:

D1 Database

Add D1 database bindings:

R2 Storage

Add R2 bucket bindings:

Preview Deployments

Test your deployment before going to production:

Local Development

During development, use Vite’s dev server:
For testing with Cloudflare-specific features locally, you can use:

Resources

Troubleshooting

Build Errors

If you encounter build errors, ensure:
  • All dependencies are installed: pnpm install
  • TypeScript compiles without errors: pnpm tsc --noEmit
  • The @cloudflare/vite-plugin is placed before tanstackStart() in plugins

Deployment Errors

If deployment fails:
  • Check your authentication: pnpm dlx wrangler whoami
  • Verify your wrangler.jsonc configuration is valid
  • Ensure compatibility date is recent
  • Check Cloudflare dashboard for quota limits

Runtime Errors

If your app fails at runtime:
  • Check the Cloudflare Workers logs in your dashboard
  • Verify all required bindings are configured
  • Ensure nodejs_compat flag is enabled for Node.js APIs
  • Test locally with wrangler dev before deploying