Next.js
Set up Prisma 8 in a Next.js app with create-prisma, from scaffold to rendered data, and deploy it to Prisma Compute.
Introduction
This guide shows you how to use Prisma 8 in a Next.js app. You scaffold a project where a server component queries your database, initialize the schema, see your data render, and deploy the app to Prisma Compute.
Every command below was run end to end against a live Prisma Postgres database.
Prerequisites
- Node.js 24 or later
- A PostgreSQL connection string, or nothing at all:
npx create-db@latestcan create a Prisma Postgres database for you
Use with your agent
To delegate this guide to your coding agent, copy the prompt below and hand it over:
1. Scaffold and enter the project
bunx create-prisma@latest create my-app --template next --provider postgres
cd my-appAnswer the prompts for contract authoring style and package manager. The scaffold generates the Next.js app with Prisma 8 wired in, installs dependencies, and emits the contract your queries are type-checked against.
Next, set the database connection for the local steps. Use your own PostgreSQL connection string, or create a Prisma Postgres database with npx create-db@latest; it prints a connection string and a claim URL you can open to keep the database. Export the variable in the shell you work in; the generated scripts read the environment variable, not .env:
export DATABASE_URL="<your connection string>"2. Initialize the database
bun run db:init"summary": "Applied 5 operation(s) across 1 space(s), database signed"If db:init stops with Connection terminated unexpectedly, a database you just created is still starting; wait a few seconds and run it again. The command is safe to repeat and reports Applied 0 operation(s) when there is nothing left to do.
db:init applies your schema (src/prisma/contract.prisma) to the database and signs it. Sample users are seeded automatically the first time the app queries the database.
3. Run and verify
bun run devOpen http://localhost (set PORT to change it). The page lists the seeded users, rendered by a server component that calls Prisma 8 directly.
4. Deploy to Prisma Compute
Next.js is supported on Prisma Compute. The scaffold declares the app for Prisma Composer in module.ts and service.ts, using the nextjs build adapter, and sets output: "standalone" in next.config.ts. Keep that setting: Compute runs the standalone server that next build emits.
Without output: "standalone" the deploy still completes, but the uploaded build contains no server to start and the live URL returns a 504. With it, the build drops from roughly 170 MB to 14 MB and boots normally.
Sign in once (it opens a browser):
bunx prisma@latest auth loginThen build and deploy from the project directory:
bun run build
bunx prisma@latest deploy module.tsmy-app
├─ database postgres-database db_abc123
└─ app compute-service cps_abc123
https://xyz.ewr.prisma.buildOpen the live URL: the page renders the seeded users. The deploy creates a project named after your module in your workspace, and re-running the deploy reuses it: the CLI finds the hosted state it stored on the first run and converges the project to your module. If a project with that name exists but the CLI cannot identify or verify its stored state (one left behind by a different checkout, for example), the deploy stops with HostedStateBootstrapError; deploy under another name with --name <unique-name>, or rename the module in module.ts. The deploy also provisions its own Prisma Postgres database on the platform, declared in module.ts; the DATABASE_URL from your local steps is not involved, and the deployed database seeds on the app's first query. For previews per Git branch and deploy-on-push, see Deploy your first app.
Where things live
src/app/page.tsx: a server component that queries users and renders themsrc/prisma/db.ts: the Prisma 8 client your components importsrc/prisma/contract.prisma: your schema
Model access is namespace-qualified on PostgreSQL: db.orm.public.User. The Prisma 8 overview covers the contract-first model behind it.
Next steps
- Change the schema in
src/prisma/contract.prisma, then runnpm run contract:emitandnpm run db:update. - Learn the fundamentals: filtering, sorting, pagination, and writes.
- Read the Prisma 8 overview for the concepts behind contracts and typed queries.
