name: cloudflare-sveltekit-workers-d1 description: Expert guidance for deploying TypeScript SvelteKit apps to Cloudflare Workers (edge) with D1. Use when configuring @sveltejs/adapter-cloudflare, Wrangler config, Workers Assets, D1 bindings/migrations, or when writing precise step-by-step deployment instructions for SvelteKit on Cloudflare Workers/Pages with D1.
Cloudflare SvelteKit Workers D1
Overview
Provide a clear, current workflow to connect a SvelteKit TypeScript app to Cloudflare Workers and D1, including adapter setup, Wrangler configuration, D1 bindings/migrations, local testing, and deployment instructions.
Workflow Decision Tree
- Existing SvelteKit app -> Use the Manual Setup workflow in
references/manual-workers-d1.md. - Brand new project -> Use the Cloudflare framework CLI flow in
references/manual-workers-d1.md(C3 option). - User wants fastest/auto config -> Use
references/wrangler-autoconfig.md(experimental) and still verify the generated config.
Core Workflow (Manual Setup)
- Verify the latest Cloudflare + SvelteKit docs with
web.run(adapter-cloudflare, Workers framework guide, D1 commands). - Add the Cloudflare adapter and update
svelte.config.js. - Create or update
wrangler.tomlfor Workers Assets and D1 bindings. - Create the D1 database and copy its binding block into
wrangler.toml. - Add TypeScript platform typings and use
platform.env.DBin server endpoints. - Create/apply migrations locally and remotely.
- Build, test with Wrangler, then deploy.
Use the exact steps and snippets in references/manual-workers-d1.md.
D1 Integration Checklist
- Ensure the binding name is a valid JS identifier and matches
platform.env.<BINDING>in code. - Ensure
wrangler.tomlincludes[[d1_databases]]withdatabase_name+database_id. - Create and apply migrations with both
--localand--remoteas needed. - Update TypeScript declarations in
src/app.d.ts.
Local Dev and Testing Guidance
- Prefer SvelteKit dev server for general UI work.
- For Cloudflare-specific behavior, build and run
wrangler dev .svelte-kit/cloudflare. - Use adapter
platformProxyoptions if local bindings need tweaks.
Writing Deployment Instructions
- Be explicit about files, commands, and where to paste blocks.
- Always include the
wrangler.tomlskeleton and D1 binding block. - Include verification steps (local dev and a deploy check).
- If there is any uncertainty in versions or commands, re-check docs via
web.run.
Resources
references/manual-workers-d1.md- canonical manual setup workflow + snippetsreferences/wrangler-autoconfig.md- experimental Wrangler auto-setup path