prisma-next-build
prisma/prisma-next
Wire Prisma Next into Vite's build system for automatic contract re-emission on save.
What is prisma-next-build?
This skill integrates Prisma Next's contract-emit plugin into your project's build tooling. Currently supports Vite 7 and 8 via @prisma-next/vite-plugin-contract-emit, which automatically re-emits contract artifacts as you edit the schema during development. Use this when setting up Vite integration or when asking about bundler support for other tools.
- Automatically re-emits Prisma Next contract artifacts (contract.d.ts and contract.json) on schema changes during vite dev
- Eliminates manual prisma-next contract emit commands during development with configurable debounce
- Integrates seamlessly with Vite 7 and 8 via a single plugin in vite.config.ts
- Surfaces contract authoring errors through Vite's error overlay for quick feedback
- Supports React Router v7 Framework Mode alongside the Vite plugin
How to install prisma-next-build
npx skills add https://github.com/prisma/prisma-next --skill prisma-next-build- Vite 7.0.0 or 8.0.0 (Vite 6 and earlier not supported)
- @prisma-next/vite-plugin-contract-emit installed as a dev dependency
- prisma-next.config.ts file in the project root or Vite root
How to use prisma-next-build
- 1.Install the plugin: pnpm add -D @prisma-next/vite-plugin-contract-emit
- 2.Add prismaVitePlugin to your vite.config.ts plugins array, passing the path to prisma-next.config.ts
- 3.Optionally configure debounceMs and logLevel in the plugin options
- 4.Start vite dev and verify the success log: [prisma-next] emitted contract.d.ts + contract.json
- 5.Edit your schema.psl file and confirm re-emit logs appear within ~150ms
- 6.For production builds, add a prebuild script: prisma-next contract emit before vite build
Use cases
- Setting up a Vite project to consume Prisma Next contracts with hot-reload during development
- Integrating Prisma Next into an existing Vite 7 or 8 application
- Configuring CI/production builds to emit contracts via prebuild scripts
- Troubleshooting contract re-emission issues during the dev loop
- Asking about bundler support for Next.js, Webpack, esbuild, Rollup, or Turbopack
- Vite 7/8 developers using Prisma Next
- Full-stack developers building with Vite and consuming contracts at runtime
- Teams setting up Prisma Next in CI/CD pipelines
- Developers seeking bundler integration guidance for unsupported tools
prisma-next-build FAQ
It watches your contract source and automatically calls prisma-next contract emit on a schedule Vite knows about, re-emitting contract.d.ts and contract.json as you edit. It's a dev-time convenience—at runtime, your app reads the contract files the same way whether the plugin emitted them or a script did.
No first-party plugins exist for those tools yet. Workaround: run prisma-next contract emit from a prebuild script in package.json and run it manually during development when the schema changes. File a feature request via prisma-next-feedback if you want a first-party plugin.
The plugin couldn't resolve contract.source.inputs from the loader, usually because the config file throws during loading or the contract source path resolves outside the Vite root. Fix the config error first, then ensure the contract source path in the config is relative to (or inside) the Vite root.
No. The plugin only runs in vite dev. For production builds, add a prebuild script that runs prisma-next contract emit before vite build.
Vite 7 and 8 only. The peer range is ^7.0.0 || ^8.0.0. Vite 6 and earlier are not supported; upgrade to use this plugin.
Full instructions (SKILL.md)
Source of truth, from prisma/prisma-next.
name: prisma-next-build description: Wire Prisma Next into the project's build system with the right build-tool plugin — Vite today via @prisma-next/vite-plugin-contract-emit (Vite 7 / 8); Next.js / Webpack / esbuild / Rollup / Turbopack are named as gaps rather than fabricated. Always offers the Vite plugin proactively when the project is using Vite. Use for vite plugin, vite-plugin, vite.config.ts, prismaVitePlugin, contract emit on save, HMR, hot reload contract, dev server, Next.js plugin, next plugin, withPrismaNext, webpack plugin, esbuild plugin, rollup plugin, build integration, dev server plugin, vite 7, vite 8.
Prisma Next — Build-System Integration
Edit your data contract. Prisma handles the rest.
This skill covers Prisma Next's build-tool plugins — the dev-server / build-system integrations that re-emit contract artifacts automatically as the user edits the contract source. Today that's @prisma-next/vite-plugin-contract-emit for Vite 7 and Vite 8. Next.js, Webpack, esbuild, Rollup, and Turbopack plugins are documented under What Prisma Next doesn't do yet with the workaround.
If the project is using Vite and consuming the contract, install the plugin. There's no good reason not to — manual prisma-next contract emit during dev is friction the plugin eliminates. The agent should proactively offer the plugin whenever it sees a vite.config.ts in the project; the user doesn't need to ask.
When to Use
- The project is using Vite (the agent sees a
vite.config.tsor@vitejs/*deps) and the contract is being consumed at runtime — proactively offer the plugin. - User asks how to wire Prisma Next into their Vite project.
- User asks about Next.js integration, Webpack integration, or any other bundler — the answer is "not yet, here's the workaround" and the skill walks them through it.
- User mentions: vite plugin, vite-plugin, vite.config.ts, prismaVitePlugin, contract emit on save, HMR, hot reload contract, dev server, vite 7, vite 8.
- User mentions Next.js / Webpack / esbuild / Rollup / Turbopack in the context of Prisma Next integration — the gap-listing path fires.
When Not to Use
- User wants to wire
db.tsand middleware →prisma-next-runtime. - User wants to file a feature request for an unbuilt bundler plugin →
prisma-next-feedback.
Key Concepts
- The plugin's job is
contract emit, on a schedule the bundler knows about. It is not a runtime concern — at runtime, the application readscontract.json/contract.d.tsthe same way whether the plugin emitted them or a script did. The plugin saves you the manual command during development. - Vite 7 and Vite 8 only. Peer range
^7.0.0 || ^8.0.0. Vite 6 is not on the support matrix. executeContractEmitis the canonical publish path. Custom plugins for other bundlers must also call it — never re-implement the load → emit → publish dance. The atomic-rename invariant (contract.d.tsrenamed beforecontract.json) and the per-output FIFO queue live in@prisma-next/cli/control-api.- No build-time / production emission. The Vite plugin runs in
vite devonly. Forvite build/ production, runprisma-next contract emitfrom aprebuildscript.
Workflow — Vite (the supported path)
1. Install the plugin
pnpm add -D @prisma-next/vite-plugin-contract-emit
(Or npm install --save-dev, yarn add -D, bun add -d — use what the project's package manager is.)
2. Wire vite.config.ts
// vite.config.ts
import { defineConfig } from 'vite';
import { prismaVitePlugin } from '@prisma-next/vite-plugin-contract-emit';
export default defineConfig({
plugins: [prismaVitePlugin('prisma-next.config.ts')],
});
The argument is the path to prisma-next.config.ts relative to Vite root. Not the path to schema.psl or contract.ts — the plugin reads the config to discover the contract source.
3. Configure (optional)
plugins: [
prismaVitePlugin('prisma-next.config.ts', {
debounceMs: 150, // delay before re-emitting (default 150)
logLevel: 'info', // 'silent' | 'info' | 'debug' (default 'info')
}),
],
Set logLevel: 'debug' only while troubleshooting; default 'info' in committed config so the dev server isn't noisy.
4. Verify the dev loop
- Start
vite dev. - Watch for the success log:
[prisma-next] emitted contract.d.ts + contract.json. - Edit
prisma/schema.psl(e.g. add a field to a model). - Within ~150ms (the debounce), watch for a re-emit log line.
- Type-check your application code that uses the new field — should pass without restarting the dev server.
If the plugin warns about config-only watching, see Common Pitfalls.
5. CI / production builds
The plugin does not run during vite build. For CI and production deploys, run prisma-next contract emit as a prebuild step:
// package.json
{
"scripts": {
"prebuild": "prisma-next contract emit",
"build": "vite build"
}
}
pnpm build then runs prebuild automatically before build.
Workflow — React Router v7 Framework Mode
The Vite plugin is compatible with @react-router/dev/vite. Both plugins are listed in vite.config.ts; there's no ordering constraint between them today, and the Prisma Next plugin's re-emit fires alongside React Router's own SSR re-load.
import { reactRouter } from '@react-router/dev/vite';
import { prismaVitePlugin } from '@prisma-next/vite-plugin-contract-emit';
export default defineConfig({
plugins: [
reactRouter(),
prismaVitePlugin('prisma-next.config.ts'),
],
});
See examples/react-router-demo for the canonical configuration plus a smoke test that proves the dev loop.
Common Pitfalls
- Pointing the plugin at
schema.pslinstead ofprisma-next.config.ts. The argument is the config path. The plugin reads the config to find the contract source. - Vite 6 or earlier. Not supported. Upgrade Vite to 7 or 8.
- The plugin warns: "watching only the config; loader resolved inputs unavailable." The plugin couldn't resolve
contract.source.inputsfrom the loader. The fallback watches onlyprisma-next.config.tsitself, so contract edits won't re-emit. Causes: the config file throws during loading; the contract source path resolves outside the Vite root. Fix the config error first, then check that the contract source path in the config is relative to (or inside) the Vite root. - Expecting
vite buildto re-emit. It doesn't. Add aprebuildscript. - Emit errors during dev: the plugin surfaces them via Vite's error overlay. Read the overlay; the underlying cause is a contract authoring problem — chain to
prisma-next-debugfor resolution (PSL syntax, missing namespace, conflicting extensions). - Re-installing dependencies without the plugin's peer-range move. When PN bumps the plugin's peer range, you must re-run
pnpm installso the lockfile picks up the new range. A stale lockfile keeps the old plugin and produces confusing version mismatch warnings.
What Prisma Next doesn't do yet
- Next.js plugin. No first-party
@prisma-next/next-plugin-*exists. Workaround: runprisma-next contract emitfrom aprebuildscript inpackage.jsonand run it manually during development when the contract changes. Many Next.js projects also run a dev-timetsx --watchagainst a small script that calls the CLI on contract-source change. If you want a first-party Next.js plugin, file a feature request via theprisma-next-feedbackskill. - Webpack, esbuild, Rollup, Turbopack plugins. None exist yet as first-party. Workaround: the canonical
executeContractEmitsurface lives in@prisma-next/cli/control-api— a small per-bundler plugin can call it from the bundler's prebuild hook, but PN doesn't ship one for you. Thevite-plugin-contract-emitsource is the reference implementation if you want to write one yourself. If you want a first-party plugin for your bundler, file a feature request via theprisma-next-feedbackskill. vite buildintegration. The plugin runs invite devonly. Workaround: aprebuildscript that runsprisma-next contract emit. If you want the plugin to also run duringvite build, file a feature request via theprisma-next-feedbackskill.- Vite 6 or earlier. Not on the support matrix. Workaround: upgrade Vite to 7 or 8. If you have a hard reason to stay on Vite 6, file a feature request via the
prisma-next-feedbackskill.
Reference Files
- The plugin's own README: https://github.com/prisma/prisma-next/blob/main/packages/1-framework/3-tooling/vite-plugin-contract-emit/README.md — support matrix, full API surface, architecture diagram, the canonical publish path warning for custom plugin authors.
- ADR 008 (Dev Auto-Emit, CI Explicit Emit) — the rationale for splitting dev-time auto-emit from the explicit CI / build step.
- ADR 032 (Dev Auto-Emit Integration) — the plugin's integration contract with the CLI control API.
Checklist
- Plugin pointed at
prisma-next.config.ts(not the contract source). - Vite version 7 or 8 (
pnpm ls vite). -
vite devlog shows the initial emit on server start. - Editing the contract source triggers a re-emit log line.
-
prebuildscript (or equivalent) runsprisma-next contract emitfor CI / production builds. - No
vite buildexpectation that the plugin will run. - For non-Vite bundlers: surfaced the What PN doesn't do yet entry and routed the user to
prisma-next-feedbackif they want first-party support. - Did NOT confabulate a
@prisma-next/next-plugin-contract-emitpackage or any other bundler-specific plugin that doesn't exist.
Related skills
More from prisma/prisma-next and the wider catalog.

prisma-next-contract
Edit the Prisma Next data contract — models, fields, relations, indexes, enums, composite types, and extensions.

prisma-next-debug
Route Prisma Next structured errors to the right recovery workflow.

prisma-next-feedback
Route Prisma Next bugs, feature requests, and Q&A to GitHub Issues or Prisma Discord.

prisma-next-migration-review
Review Prisma Next migrations, resolve conflicts, and manage deployment refs for CI.

prisma-next-migrations
Author Prisma Next migrations with data transforms and error recovery.

prisma-next-queries
Write Prisma Next queries for Postgres, SQLite, or Mongo with ORM and SQL builder lanes.