TanStack Start
This guide shows how to initialize and deploy a TanStack Start application to Cloudflare using Alchemy.
Init
Start by creating a new TanStack Start project with Alchemy:
bunx alchemy create my-tanstack-app --template=tanstack-start
cd my-tanstack-app
npx alchemy create my-tanstack-app --template=tanstack-start
cd my-tanstack-app
pnpm dlx alchemy create my-tanstack-app --template=tanstack-start
cd my-tanstack-app
yarn dlx alchemy create my-tanstack-app --template=tanstack-start
cd my-tanstack-app
Log in to Cloudflare
Authenticate once with your Cloudflare account:
bun wrangler login
npx wrangler login
pnpm wrangler login
yarn wrangler login
TIP
Alchemy automatically re-uses your Wrangler OAuth tokens. See the Cloudflare Auth guide for other options.
Deploy
Run the deploy script generated by the template:
bun run deploy
npm run deploy
pnpm run deploy
yarn run deploy
You'll get the live URL of your TanStack Start application:
{
url: "https://website.<your-account>.workers.dev",
}
Local Development
Work locally using the dev script:
bun run dev
npm run dev
pnpm run dev
yarn run dev
Destroy
Clean up all Cloudflare resources created by this stack:
bun run destroy
npm run destroy
pnpm run destroy
yarn run destroy
Explore
.env
Alchemy requires a locally set password to encrypt Secrets that are stored in state. Be sure to change this.
NOTE
See the Secret documentation to learn more.
ALCHEMY_PASSWORD=change-me
alchemy.run.ts
/// <reference types="@types/node" />
import alchemy from "alchemy";
import { TanStackStart } from "alchemy/cloudflare";
const app = await alchemy("my-tanstack-app");
export const worker = await TanStackStart("website", {
command: "bun run build",
});
console.log({
url: worker.url,
});
await app.finalize();
types/env.d.ts
// Auto-generated Cloudflare binding types.
// @see https://alchemy.run/docs/concepts/bindings.html#type-safe-bindings
import type { worker } from "../alchemy.run.ts";
export type CloudflareEnv = typeof worker.Env;
declare global {
type Env = CloudflareEnv;
}
declare module "cloudflare:workers" {
namespace Cloudflare {
export interface Env extends CloudflareEnv {}
}
}
tsconfig.json
The CLI updated the tsconfig.json
to include alchemy.run.ts
and register @cloudflare/workers-types
+ types/env.d.ts
globally
TIP
The alchemy.run.ts
script will be run by node
but still needs to infer the Binding types which depends on @cloudflare/workers-types
:
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022"],
"module": "ES2022",
"moduleResolution": "bundler",
"strict": true,
"skipLibCheck": true,
"types": ["@cloudflare/workers-types", "./types/env.d.ts"]
},
"include": ["types/**/*.ts", "alchemy.run.ts", "src/**/*.ts"]
}