| 1 | --- |
| 2 | title: TanStack Start |
| 3 | description: Deploy TanStack Start to Prisma Compute with Prisma.Website.TanStackStart — React or Solid SSR on Bun, with native Vite dev locally. |
| 4 | sidebar: |
| 5 | order: 8 |
| 6 | --- |
| 7 | |
| 8 | import { Code, Tabs, TabItem } from "@astrojs/starlight/components"; |
| 9 | |
| 10 | export const devDeps = "@alchemy.run/frontend-frameworks @vercel/nft"; |
| 11 | |
| 12 | `Prisma.Website.TanStackStart` builds [TanStack Start](https://tanstack.com/start) |
| 13 | for React or Solid through your project's Vite pipeline. The shared |
| 14 | Node target wraps its fetch handler as an HTTP server; SSR and client |
| 15 | assets run on **Bun in Prisma Compute** from a `tar.gz` upload. There |
| 16 | is no Docker image or registry. |
| 17 | |
| 18 | ## Install |
| 19 | |
| 20 | Install the build-time integration; the resource loads `/tanstack-start` |
| 21 | and `/tanstack-start/node` from your project: |
| 22 | |
| 23 | <Tabs syncKey="pkgManager"> |
| 24 | <TabItem label="bun" icon="bun"><Code code={`bun add -d ${devDeps}`} lang="sh" /></TabItem> |
| 25 | <TabItem label="npm" icon="npm"><Code code={`npm install -D ${devDeps}`} lang="sh" /></TabItem> |
| 26 | <TabItem label="pnpm" icon="pnpm"><Code code={`pnpm add -D ${devDeps}`} lang="sh" /></TabItem> |
| 27 | <TabItem label="yarn" icon="seti:yarn"><Code code={`yarn add -D ${devDeps}`} lang="sh" /></TabItem> |
| 28 | </Tabs> |
| 29 | |
| 30 | ## Configure Vite |
| 31 | |
| 32 | Keep the framework plugin and normal Vite plugins. For React: |
| 33 | |
| 34 | ```typescript |
| 35 | // vite.config.ts |
| 36 | import tailwindcss from "@tailwindcss/vite"; |
| 37 | import { tanstackStart } from "@tanstack/react-start/plugin/vite"; |
| 38 | import viteReact from "@vitejs/plugin-react"; |
| 39 | import { defineConfig } from "vite"; |
| 40 | |
| 41 | export default defineConfig({ |
| 42 | plugins: [tailwindcss(), tanstackStart(), viteReact()], |
| 43 | }); |
| 44 | ``` |
| 45 | |
| 46 | The integration drives `builder.buildApp()` and makes the SSR bundle |
| 47 | self-contained. No deployment adapter is required. |
| 48 | |
| 49 | :::caution[Remove the Cloudflare Vite plugin] |
| 50 | If the scaffold includes `@cloudflare/vite-plugin`, remove it. It |
| 51 | builds for workerd, not the Node-compatible target hosted on Prisma: |
| 52 | |
| 53 | ```diff lang="typescript" |
| 54 | -import { cloudflare } from "@cloudflare/vite-plugin"; |
| 55 | import { tanstackStart } from "@tanstack/react-start/plugin/vite"; |
| 56 | import viteReact from "@vitejs/plugin-react"; |
| 57 | import { defineConfig } from "vite"; |
| 58 | |
| 59 | export default defineConfig({ |
| 60 | - plugins: [cloudflare({ viteEnvironment: { name: "ssr" } }), tanstackStart(), viteReact()], |
| 61 | + plugins: [tanstackStart(), viteReact()], |
| 62 | }); |
| 63 | ``` |
| 64 | |
| 65 | ::: |
| 66 | |
| 67 | ## Declare the Website |
| 68 | |
| 69 | ```typescript |
| 70 | // alchemy.run.ts |
| 71 | import * as Prisma from "alchemy/Prisma"; |
| 72 | |
| 73 | export const Website = Prisma.Website.TanStackStart("Website", { |
| 74 | rootDir: "./app", |
| 75 | }); |
| 76 | ``` |
| 77 | |
| 78 | Omit `rootDir` for an app at `.`. Live deploy creates a database-less |
| 79 | Prisma project if `project` is omitted; pass an existing project to |
| 80 | share it with other apps. |
| 81 | |
| 82 | ## Add it to the Stack |
| 83 | |
| 84 | ```typescript |
| 85 | // alchemy.run.ts |
| 86 | import * as Alchemy from "alchemy"; |
| 87 | import * as Effect from "effect/Effect"; |
| 88 | |
| 89 | export default Alchemy.Stack( |
| 90 | "MyTanStackSite", |
| 91 | { providers: Prisma.providers(), state: Alchemy.localState() }, |
| 92 | Effect.gen(function* () { |
| 93 | const site = yield* Website; |
| 94 | return { url: site.url }; |
| 95 | }), |
| 96 | ); |
| 97 | ``` |
| 98 | |
| 99 | Client assets are served first; misses go to SSR, server routes, or |
| 100 | server functions. `site.url` is the Compute endpoint on deploy. |
| 101 | |
| 102 | ## Add environment variables |
| 103 | |
| 104 | ```diff lang="typescript" |
| 105 | export const Website = Prisma.Website.TanStackStart("Website", { |
| 106 | rootDir: "./app", |
| 107 | + env: { API_BASE: "https://api.example.com" }, |
| 108 | }); |
| 109 | ``` |
| 110 | |
| 111 | `env` is applied before build and dev and passed to Compute. Vite |
| 112 | inlines `VITE_*` values into the browser bundle; keep secrets out of |
| 113 | those keys. Sibling outputs can feed `env` inside the Stack generator. |
| 114 | |
| 115 | ## Read the environment in a server function |
| 116 | |
| 117 | ```typescript |
| 118 | // src/routes/index.tsx |
| 119 | import { createServerFn } from "@tanstack/react-start"; |
| 120 | |
| 121 | const getApiBase = createServerFn({ method: "GET" }).handler(() => ({ |
| 122 | apiBase: process.env.API_BASE ?? "unset", |
| 123 | })); |
| 124 | ``` |
| 125 | |
| 126 | Server functions run on Bun and read `process.env`. |
| 127 | |
| 128 | ## Read the environment in a server route |
| 129 | |
| 130 | ```typescript |
| 131 | // src/routes/api.hello.ts |
| 132 | import { createFileRoute } from "@tanstack/react-router"; |
| 133 | |
| 134 | export const Route = createFileRoute("/api/hello")({ |
| 135 | server: { |
| 136 | handlers: { |
| 137 | GET: () => new Response(process.env.API_BASE ?? "unset"), |
| 138 | }, |
| 139 | }, |
| 140 | }); |
| 141 | ``` |
| 142 | |
| 143 | Server routes use the same process environment. |
| 144 | |
| 145 | ## Build configuration |
| 146 | |
| 147 | Your `vite.config.ts` is the build configuration. Keep Vite's default |
| 148 | output directory, `dist`; the integration reads `dist/server` and |
| 149 | `dist/client`. Static files are served by Compute, not deployed as an |
| 150 | independent CDN site. |
| 151 | |
| 152 | ## Local dev |
| 153 | |
| 154 | `bun alchemy dev` starts TanStack Start's native Vite server with HMR |
| 155 | and creates no Prisma resources for the Website. Opt into live deployment |
| 156 | during dev explicitly: |
| 157 | |
| 158 | ```typescript |
| 159 | export const Website = Prisma.Website.TanStackStart("Website").pipe( |
| 160 | Alchemy.remote(), |
| 161 | ); |
| 162 | ``` |
| 163 | |
| 164 | ## Custom domain |
| 165 | |
| 166 | ```typescript |
| 167 | const site = yield* Prisma.Website.TanStackStart("Web", { |
| 168 | domain: "app.example.com", |
| 169 | }); |
| 170 | ``` |
| 171 | |
| 172 | `Prisma.CustomDomain` requires the app to be on the current default |
| 173 | branch. Configure returned DNS records yourself and verify status before |
| 174 | cutover; see [Custom domains](/prisma/frontend/websites#custom-domains). |
| 175 | |
| 176 | ## Where next |
| 177 | |
| 178 | - [TanStack Start API](/providers/prisma/website/tanstackstart). |
| 179 | - [TanStack Start example](https://github.com/alchemy-run/alchemy/tree/main/examples/prisma-website-tanstack-start). |
| 180 | - [Websites](/prisma/frontend/websites) and [Compute apps](/prisma/compute/apps). |