Skip to main content
Prisma Documentation Docs

Search documentation

Type to search this documentation.

On this pageOverview

contract emit

contract emit reads your contract source (TypeScript or Prisma schema) and writes the generated artifacts used by the runtime, verification, and migration tooling.

The command is offline. It does not need a database connection.

A Prisma schema source can be one .prisma file or a glob that matches several files; see Split the schema across several files. contract emit reads only the .prisma files whose first line is // use prisma-8, and skips any other file without a warning. When no file starts with that line, it fails with CONTRACT.SOURCE_LOAD_FAILED and reports the problem with the code PSL_NO_OPTED_IN_SCHEMA_FILES.

title="bun"
bunx prisma contract emit
pnpm
pnpm prisma contract emit
yarn
yarn prisma contract emit
npm
npx prisma contract emit
Option What it does
--output-path <dir> Writes contract.json and contract.d.ts into a specific directory.
--config <path> Read this config file instead of ./prisma.config.ts.
--json Prints a machine-readable result.

The command emits:

  • contract.json, the canonical machine-readable contract
  • contract.d.ts, the generated TypeScript contract declarations

Do not edit these files by hand. Re-run contract emit after changing the contract source or extension pack list. The first emit after you upgrade from a release before 8.0.0-rc.12 reorders the entries in contract.d.ts to follow the order in contract.json, which needs no change to your code. The first emit after you upgrade to 8.0.0-rc.13 renames two keys in contract.json: each generated default under execution.mutations.defaults names its target as entry and field instead of table and column. The client refuses a contract that has the old keys, so run contract emit after you upgrade. contract emit does not rewrite the contract snapshots under migrations/snapshots/. In each snapshot that has an execution section, rename table to entry and column to field in every ref under execution.mutations.defaults, in both contract.json and contract.d.ts. Leave the snapshot's executionHash as it is.

When the contract source cannot be read, the command fails with CONTRACT.SOURCE_LOAD_FAILED and prints each finding, meaning each problem it found in the source, with the file and line where it knows them. In --json output, the findings are the entries of the envelope.diagnostics array in the final result event, next to envelope.error. Each entry has a code, a summary, and, where known, where.path and where.line. If an entry's code is CONTRACT.SOURCE_DIAGNOSTIC, the code of the specific problem, such as PSL_NO_OPTED_IN_SCHEMA_FILES, is in its meta.code.

In development, a Vite plugin runs contract emit for you: once when the dev server starts, and again whenever the contract source or prisma.config.ts changes. It needs Vite 7 or 8, and comes with your database package, so there is nothing to install:

title="vite.config.ts"
import { defineConfig } from "vite";

import { prismaVitePlugin } from "@prisma/orm-postgres/vite-plugin-contract-emit";

export default defineConfig({

  plugins: [prismaVitePlugin()],

});

On MongoDB, import it from @prisma/orm-mongo/vite-plugin-contract-emit. The plugin reads prisma.config.ts from the Vite root; pass another path as the first argument, prismaVitePlugin("config/prisma.config.ts"). A second argument takes debounceMs (how long to wait after a change before emitting, 150 by default) and logLevel ("silent", "info", or "debug"). The dev server prints one line per emit:

[prisma-vite-plugin-contract-emit] Emitted contract (storageHash: ab5014a0...)

An emit that fails shows in Vite's error overlay. The plugin does nothing in a production build, so builds and CI still run the command themselves. With any other bundler, or for a build, add the command as a prebuild script, which npm, pnpm, and yarn run before build:

(excerpt)"
{

  "scripts": {

    "prebuild": "prisma contract emit",

    "build": "next build"

  }

}
title="bun"
bunx prisma contract emit

bunx prisma contract emit --output-path ./generated

bunx prisma contract emit --json
pnpm
pnpm prisma contract emit
pnpm prisma contract emit --output-path ./generated
pnpm prisma contract emit --json
yarn
yarn prisma contract emit
yarn prisma contract emit --output-path ./generated
yarn prisma contract emit --json
npm
npx prisma contract emit
npx prisma contract emit --output-path ./generated
npx prisma contract emit --json

After emitting, choose the database workflow:

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu