Installation
Install the required dependencies:Configuration
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
import viteReact from "@vitejs/plugin-react";
import alchemy from "alchemy/cloudflare/tanstack-start";
import { defineConfig } from "vite";
const config = defineConfig({
plugins: [
alchemy(),
tanstackStart(),
viteReact(),
],
});
export default config;
import { createRequestHandler } from "@tanstack/react-start-cloudflare";
import * as build from "@tanstack/react-start/server-entry";
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
const handler = createRequestHandler({ build });
return handler(request, { env, ctx });
},
};
import alchemy from "alchemy";
import { KVNamespace, TanStackStart } from "alchemy/cloudflare";
const app = await alchemy("my-tanstack-app");
const kv = await KVNamespace("kv", {
title: `${app.name}-${app.stage}-kv`,
});
const website = await TanStackStart("website", {
bindings: {
KV: kv,
API_SECRET: alchemy.secret.env.API_SECRET,
},
});
console.log({
url: website.url,
});
await app.finalize();
Configuration Options
Properties
bindings: Cloudflare bindings (KV, R2, D1, etc.)entrypoint: Worker entrypoint path- Default:
dist/server/index.js
- Default:
assets: Static assets directory- Default:
dist/client
- Default:
wrangler.main: Path to server entry point- Default:
src/server.ts(if exists), otherwise uses@tanstack/react-start/server-entry
- Default:
compatibility: Node.js compatibility mode- Default:
"node"
- Default:
noBundle: Skip bundling- Default:
true
- Default:
Accessing Bindings
Access Cloudflare bindings in your TanStack Start application:Server Functions
API Routes
Loaders
TypeScript Configuration
Define types for your Cloudflare bindings:Local Development
Start the TanStack Start dev server:- Local emulation of Cloudflare bindings
- Hot module replacement
- Fast refresh
Custom Dev Configuration
Server Entry Point
The resource automatically detects your server entry point:- If
src/server.tsexists, it will be used - Otherwise, falls back to
@tanstack/react-start/server-entry
Custom Server Entry
Specify a custom server entry:Node.js Compatibility
TanStack Start automatically enables Node.js compatibility:- Node.js built-in modules
- npm packages with Node.js dependencies
- Full TanStack Start feature set
Deployment Best Practices
- Keep
dist/directory in.gitignore - Use environment variables for secrets via
alchemy.secret.env.X - Test locally with Vite dev server
- Configure proper TypeScript types for bindings
- Use server functions for data fetching
Related Resources
- Website - Base resource for web applications
- Worker - Cloudflare Workers deployment
- KV Namespace - Key-value storage
- D1 Database - SQL database