rembrembdocs

Generators in your Prisma schema specify what assets are generated when the `prisma generate` command is invoked. This page explains how to configure generators

A Prisma schema can have one or more generators, represented by the generator block:

generator client {
  provider = "prisma-client"
  output   = "../generated/prisma"
}

A generator determines which assets are created when you run the prisma generate command.

The default generator for Prisma Client is prisma-client, which outputs plain TypeScript code and requires a custom output path (read more about it here).

Alternatively, you can configure any npm package that complies with our generator specification.

The new prisma-client generator offers greater control and flexibility when using Prisma ORM across different JavaScript environments (such as ESM, Bun, Deno, ...).

It generates Prisma Client into a custom directory in your application's codebase that's specified via the output field on the generator block. This gives you full visibility and control over the generated code. It also splits the generated Prisma Client library into multiple files.

This generator ensures you can bundle your application code exactly the way you want, without relying on hidden or automatic behaviors.

Here are the main differences compared to prisma-client-js:

The prisma-client generator is the default generator.

Getting started

Follow these steps to use the new prisma-client generator in your project.

1. Configure the prisma-client generator in schema.prisma

Update your generator block:

prisma/schema.prisma

generator client {
  provider = "prisma-client"            // Required
  output   = "../src/generated/prisma"  // Required
}

The output option is required and tells Prisma ORM where to put the generated Prisma Client code. You can choose any location suitable for your project structure. For instance, if you have the following layout:

.
├── package.json
├── prisma
│   └── schema.prisma
├── src
│   └── index.ts
└── tsconfig.json

Then ../src/generated/prisma places the generated code in src/generated/prisma relative to schema.prisma.

2. Generate Prisma Client

Generate Prisma Client by running:

This generates the code for Prisma Client (including the query engine binary) into the specified output folder.

3. Use Prisma Client in your application

Importing Prisma Client

After generating the Prisma Client, import it from the path you specified:

src/index.ts

import { PrismaClient } from "./generated/prisma/client";
import { PrismaPg } from "@prisma/adapter-pg"; // or the adapter for your database
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
const prisma = new PrismaClient({ adapter });

Prisma Client is now ready to use in your project.

Importing generated model types

If you're importing types generated for your models, you can do so as follows:

src/index.ts

import { UserModel, PostModel } from "./generated/prisma/models";

Importing generated enum types

If you're importing types generated for your enums, you can do so as follows:

src/index.ts

import { Role, User } from "./generated/prisma/enums";

Importing in browser environments

If you need to access generated types in your frontend code, you can import them as follows:

src/index.ts

import { Role } from "./generated/prisma/browser";

Note that ./generated/prisma/browser does not expose a PrismaClient.

Field reference

Use the following options in the generator client { ... } block. Only output is required. The other fields have defaults or are inferred from your environment and tsconfig.json.

schema.prisma

generator client {
  // Required
  provider = "prisma-client"
  output   = "../src/generated/prisma"

  // Optional
  engineType             = "client"
  runtime                = "nodejs"
  moduleFormat           = "esm"
  generatedFileExtension = "ts"
  importFileExtension    = "ts"
}

Below are the options for the prisma-client generator:

OptionDefaultDescription
output (required)Directory where Prisma Client is generated, e.g. ../src/generated/prisma.
runtimenodejsTarget runtime environment.
Supported values:
nodejs, deno, bun, workerd (alias cloudflare), vercel-edge (alias edge-light), react-native.
moduleFormatInferred from environmentModule format (esm or cjs). Determines whether import.meta.url or __dirname is used.
generatedFileExtensiontsFile extension for generated TypeScript files (ts, mts, cts).
importFileExtensionInferred from environmentFile extension used in import statements. Can be ts, mts, cts, js, mjs, cjs, or empty (for bare imports).

Importing types

The new prisma-client generator creates individual .ts files which allow for a more fine granular import of types. This can improve compile and typecheck performance and be useful for tree-shaking, too. You can still use the top level barrel files that export all types through a single import.

The overall structure of the generated output looks like this:

generated/
└── prisma
    ├── browser.ts
    ├── client.ts
    ├── commonInputTypes.ts
    ├── enums.ts
    ├── internal
    │   ├── ...
    ├── models
    │   ├── Post.ts
    │   └── User.ts
    └── models.ts

client.ts

For use in your server code.

Example:

src/index.ts

import { Prisma, type Post, PrismaClient } from "./generated/prisma/client";

browser.ts

For using types in your frontend (i.e. code that runs in the browser).

Example:

src/index.ts

import { Prisma, type Post } from "./generated/prisma/browser";

enums.ts

Isolated access to user defined enum types and values.

Example:

src/index.ts

import { MyEnum } from "./generated/prisma/enums";

models.ts

Isolated access to all model types.

Example:

src/index.ts

import type {
  UserModel,
  PostModel,
  PostWhereInput,
  UserUpdateInput,
} from "./generated/prisma/models";

models/<ModelName>.ts

Isolated access to the types for an individual model.

Example:

src/index.ts

import type { UserModel, UserWhereInput, UserUpdateInput } from "./generated/prisma/models/User";

commonInputTypes.ts

Provides shared utility types that you should rarely directly need.

Example:

import type { IntFilter } from "./generated/prisma/commonInputTypes";

internal/*

Breaking changes from prisma-client-js

Examples

To see what the new prisma-client generator looks like in practice, check out our minimal and ready-to-run examples:

The prisma-client-js generator requires the @prisma/client npm package and generates Prisma Client into node_modules.

Field reference

The generator for Prisma's JavaScript Client accepts multiple additional properties:

prisma/schema.prisma

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["sample-preview-feature"]
  binaryTargets   = ["debian-openssl-1.1.x"] // defaults to `"native"`
}

The following is a list of community created generators.