# TanStack Start (/docs/guides/next/frameworks/tanstack-start)

> For the complete Prisma documentation index, see [llms.txt](https://www.prisma.io/docs/llms.txt). A markdown version of any docs page is available by appending `.md` to its URL.

Set up Prisma Next in a TanStack Start app with create-prisma, from scaffold to rendered data, and deploy it to Prisma Compute.

Location: Guides > Next > Frameworks > TanStack Start

## Introduction [#introduction]

This guide shows you how to use Prisma Next in a TanStack Start app. You scaffold a project where a server function queries your database and a route loader feeds it to the page, initialize the schema, see your data, and deploy the app to [Prisma Compute](https://www.prisma.io/docs/compute).

Every command below was run end to end against a live [Prisma Postgres](https://www.prisma.io/docs/postgres) database.

## Quick start [#quick-start]

One command scaffolds the project with Prisma Next wired in:

  

#### bun

```bash
bunx create-prisma@next create my-app --template tanstack-start --provider postgres
```

#### pnpm

```bash
pnpm dlx create-prisma@next create my-app --template tanstack-start --provider postgres
```

#### yarn

```bash
yarn dlx create-prisma@next create my-app --template tanstack-start --provider postgres
```

#### npm

```bash
npx create-prisma@next create my-app --template tanstack-start --provider postgres
```

Pick Prisma Postgres at the database prompt to have a database created for you, or paste your own `DATABASE_URL`.

## Prerequisites [#prerequisites]

* [Node.js](https://nodejs.org) 24 or later
* A PostgreSQL connection string, or nothing at all: the scaffold can create the database for you

## Use with your agent [#use-with-your-agent]

Prefer to delegate this guide? Copy the prompt and hand it to your coding agent:

```text
Create a new TanStack Start app with Prisma Next, seed it, and deploy it to Prisma Compute.

1. Scaffold: `npx create-prisma@next create my-app --template tanstack-start --provider postgres --prisma-postgres --yes` (or pass `--database-url "<url>"` instead of `--prisma-postgres` if I give you a connection string).
2. In `my-app`, run `npm run db:init`, then `npm run db:seed`. If seeding fails with `Cannot read properties of undefined (reading 'where')`, change `db.orm.User` to `db.orm.public.User` in `src/prisma/seed.ts` and `src/prisma/users.ts`, then rerun.
3. Start `npm run dev` in the background, wait until it reports ready, verify http://localhost:3000 renders the three seeded users, then stop the dev server.
4. Prepare the deploy build: install `nitro` and enable the `nitro()` Vite plugin for builds only, following https://www.prisma.io/docs/guides/next/frameworks/tanstack-start.md.
5. Deploy: check `npx @prisma/cli@latest auth whoami`; if I am not signed in, stop and ask me to run `npx @prisma/cli@latest auth login`. Then run `npx @prisma/cli@latest app deploy --create-project my-app --env .env` and verify the live URL renders the seeded users.

Use the installed Prisma Next skills.
```

## 1. Scaffold and enter the project [#1-scaffold-and-enter-the-project]

  

#### bun

```bash
bunx create-prisma@next create my-app --template tanstack-start --provider postgres
cd my-app
```

#### pnpm

```bash
pnpm dlx create-prisma@next create my-app --template tanstack-start --provider postgres
cd my-app
```

#### yarn

```bash
yarn dlx create-prisma@next create my-app --template tanstack-start --provider postgres
cd my-app
```

#### npm

```bash
npx create-prisma@next create my-app --template tanstack-start --provider postgres
cd my-app
```

The scaffold writes your connection string to `.env`, generates the TanStack Start app with Prisma Next wired in, installs dependencies, and emits the contract your queries are type-checked against.

## 2. Initialize and seed the database [#2-initialize-and-seed-the-database]

  

#### bun

```bash
bun run db:init
bun run db:seed
```

#### pnpm

```bash
pnpm run db:init
pnpm run db:seed
```

#### yarn

```bash
yarn db:init
yarn db:seed
```

#### npm

```bash
npm run db:init
npm run db:seed
```

```text no-copy
"summary": "Applied 5 operation(s) across 1 space(s), database signed"
Seeded 3 users.
```

`db:init` applies your schema (`src/prisma/contract.prisma`) to the database and signs it; the seed gives the first page something to show.

> [!NOTE]
> Seeing `Cannot read properties of undefined (reading 'where')`? The current `tanstack-start` template still generates the older unqualified query form. Update `db.orm.User` to `db.orm.public.User` in `src/prisma/seed.ts` and `src/prisma/users.ts`, then rerun `db:seed`. The home page reads through `src/prisma/users.ts`, so until both files are updated it shows "Could not query users yet" instead of the user list.

## 3. Run and verify [#3-run-and-verify]

  

#### bun

```bash
bun run dev
```

#### pnpm

```bash
pnpm run dev
```

#### yarn

```bash
yarn dev
```

#### npm

```bash
npm run dev
```

Open [http://localhost:3000](http://localhost:3000). The page lists the seeded users, provided by the route loader's server function.

## 4. Deploy to Prisma Compute [#4-deploy-to-prisma-compute]

TanStack Start is supported on [Prisma Compute](https://www.prisma.io/docs/compute), so the app can go from your terminal to a live URL. The Compute build expects Nitro's `.output` directory, and the template builds with plain Vite, so first install the `nitro` package (not `nitropack`):

  

#### bun

```bash
bun add nitro
```

#### pnpm

```bash
pnpm add nitro
```

#### yarn

```bash
yarn add nitro
```

#### npm

```bash
npm install nitro
```

Then enable `nitro()` from `nitro/vite` for builds only:

```ts title="vite.config.ts"
import { prismaVitePlugin } from "@prisma-next/vite-plugin-contract-emit";
import { defineConfig } from "vite";
import viteReact from "@vitejs/plugin-react";
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
import { nitro } from "nitro/vite";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig(({ command }) => ({
  plugins: [
    prismaVitePlugin(),
    tsconfigPaths({ projects: ["./tsconfig.json"] }),
    tanstackStart(),
    ...(command === "build" ? [nitro()] : []),
    viteReact(),
  ],
}));
```

The Nitro plugin is enabled for builds only because it conflicts with the contract watcher in the dev server; `npm run dev` keeps working unchanged.

Sign in once (it opens a browser):

  

#### bun

```bash
bunx @prisma/cli@latest auth login
```

#### pnpm

```bash
pnpm dlx @prisma/cli@latest auth login
```

#### yarn

```bash
yarn dlx @prisma/cli@latest auth login
```

#### npm

```bash
npx @prisma/cli@latest auth login
```

Then deploy from the project directory. The `--env .env` flag passes your `DATABASE_URL` to the deployment, so the live app reads the same database:

  

#### bun

```bash
bunx @prisma/cli@latest app deploy --env .env
```

#### pnpm

```bash
pnpm dlx @prisma/cli@latest app deploy --env .env
```

#### yarn

```bash
yarn dlx @prisma/cli@latest app deploy --env .env
```

#### npm

```bash
npx @prisma/cli@latest app deploy --env .env
```

```text no-copy
First deploy of "my-app" -- promoting to production.

Build settings
  Build Command     npm run build  · package.json scripts.build
  Output Directory  .output        · TanStack Start output

Building locally...
  Built      0.5 MB
Uploading...
Deploying...
Live in 9.4s
https://<your-app>.ewr.prisma.build
```

Open the live URL: the page renders the same seeded users, served from your Prisma Postgres database. The first deploy asks you to pick or create a project (pass `--create-project my-app` to skip the prompt), pins the directory to it in a gitignored `.prisma/local.json`, and promotes to production. For previews per Git branch and deploy-on-push, see [Deploy your first app](https://www.prisma.io/docs/prisma-compute/deploy).

## Where things live [#where-things-live]

* `src/routes/index.tsx`: the route: a `createServerFn` queries users, the loader passes them to the page
* `src/prisma/users.ts`: the query helper the server function calls
* `src/prisma/db.ts`: the Prisma Next client behind it

Model access is namespace-qualified on PostgreSQL: `db.orm.public.User`. The [Prisma Next overview](https://www.prisma.io/docs/orm/next) covers the contract-first model behind it.

## Next steps [#next-steps]

* Change the schema in `src/prisma/contract.prisma`, then run `npm run contract:emit` and `npm run db:update`.
* [Learn the fundamentals](https://www.prisma.io/docs/orm/next/fundamentals/reading-data): filtering, sorting, pagination, and writes.
* [Read the Prisma Next overview](https://www.prisma.io/docs/orm/next) for the concepts behind contracts and typed queries.

## Related pages

- [`Astro`](https://www.prisma.io/docs/guides/next/frameworks/astro): Set up Prisma Next in an Astro app with create-prisma, from scaffold to rendered data, and deploy it to Prisma Compute.
- [`Elysia`](https://www.prisma.io/docs/guides/next/frameworks/elysia): Build an Elysia API on Prisma Next with the elysia template and deploy it to Prisma Compute.
- [`Hono`](https://www.prisma.io/docs/guides/next/frameworks/hono): Build a Hono API on Prisma Next with the hono template, add your own routes, and deploy it to Prisma Compute.
- [`NestJS`](https://www.prisma.io/docs/guides/next/frameworks/nestjs): Set up Prisma Next in a NestJS app with create-prisma, from scaffold to seeded API to a live deploy on Prisma Compute.
- [`Next.js`](https://www.prisma.io/docs/guides/next/frameworks/nextjs): Set up Prisma Next in a Next.js app with create-prisma, from scaffold to rendered data, and deploy it to Prisma Compute.