Skip to main content
Prisma Documentation Docs

Search documentation

Type to search this documentation.

On this pageOverview

Generators (Prisma ORM v7) (/docs/orm/v7/prisma-schema/overview/generators)

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

Location: ORM > v7 > Prisma Schema > Overview > Generators

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

prisma
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 in the blog post on generating into node_modules).

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

The prisma-client generator outputs plain TypeScript that runs across 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.

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

  • Requires an output path; no "magic" generation into node_modules any more
  • Doesn't load .env at runtime; use dotenv or set environment variables manually instead
  • Supports ESM and CommonJS via the moduleFormat field
  • More flexible thanks to additional fields
  • Outputs plain TypeScript that's bundled just like the rest of your application code

The prisma-client generator is the default generator.

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

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

Section titled “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:

Text
.
├── 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.

Generate Prisma Client by running:

Bash
bunx prisma generate
Bash
pnpm prisma generate
Bash
yarn prisma generate
Bash
npx prisma generate

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

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.

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";

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";

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.

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:

Option Default Description
output (required) Directory where Prisma Client is generated, e.g. ../src/generated/prisma.
runtime nodejs Target runtime environment.
Supported values:
nodejs, deno, bun, workerd (alias cloudflare), vercel-edge (alias edge-light), react-native.
moduleFormat Inferred from environment Module format (esm or cjs). Determines whether import.meta.url or __dirname is used.
generatedFileExtension ts File extension for generated TypeScript files (ts, mts, cts).
importFileExtension Inferred from environment File extension used in import statements. Can be ts, mts, cts, js, mjs, cjs, or empty (for bare imports).

[!NOTE] nodejs, deno, and bun all map to the same internal codepath but are preserved as separate user-facing values for clarity.

[!NOTE] If you use tsx as your TypeScript runner and see Cannot find module './internal/class.js' errors at runtime, set importFileExtension = "ts" in your generator block:

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

This happens because the generated client uses .js extensions in its import statements (ESM convention), but tsx cannot resolve .js imports to the corresponding .ts files on disk. Setting importFileExtension = "ts" ensures the generated imports match what tsx expects.

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

For use in your server code.

  • Provides access to the PrismaClient instance and all model and utility types.
  • Provides best compatibility with the prisma-client-js generated output.
  • Contains transitive dependencies on server only-packages, so cannot be used in browser contexts.

Example:

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

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

  • Contains no transitive dependencies on Node.js or other server-only packages.
  • Contains no real PrismaClient constructor.
  • Contains all model and enum types and values.
  • Provides access to various utilities like Prisma.JsonNull and Prisma.Decimal.

Example:

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

Isolated access to user defined enum types and values.

  • Contains no transitive dependencies and is very slim.
  • Can be used on backend and frontend.
  • Prefer this for optimal tree shaking and typecheck performance when accessing enums.

Example:

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

Isolated access to all model types.

  • Can be used on backend and frontend.
  • Contains all models including their derived utility types like <ModelName>WhereInput or <ModelName>UpdateInput>.

[!NOTE] Plain model types are exposed here as <ModelName>Model (e.g. PostModel). This is in contrast to the exposed name in client.ts and browser.ts which is simply <ModelName> (e.g. Post).

This is necessary due to internal constraints to avoid potential naming conflicts with internal types.

Example:

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

Isolated access to the types for an individual model.

  • Can be used on backend and frontend.
  • Contains the models including its derived utility types like <ModelName>WhereInput or <ModelName>UpdateInput>.

[!NOTE] The plain model type is exposed here as <ModelName>Model (e.g. PostModel).

Example:

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

Provides shared utility types that you should rarely directly need.

Example:

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

[!WARNING] Do not directly import from these files! They are not part of the stable API of the generated code and can change at any time in breaking ways.

Usually anything you might need from there is exposed via browser.ts or client.ts under the Prisma namespace.

  • Requires an output path on the generator block
  • No Prisma.validator function; you can use TypeScript native satisfies keyword instead

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

Example Framework Bundler Runtime Monorepo
nextjs-starter-webpack Next.js 15 Webpack Node.js n/a
nextjs-starter-turbopack Next.js 15 Turbopack (alpha) Node.js n/a
nextjs-starter-webpack-monorepo Next.js 15 Webpack Node.js pnpm
nextjs-starter-webpack-with-middleware Next.js 15 Webpack Node.js (main pages), vercel-edge (middleware) n/a
nextjs-starter-webpack-turborepo Next.js 15 Webpack Node.js turborepo
react-router-starter-nodejs React Router 7 Vite 6 Node.js n/a
react-router-starter-cloudflare-workerd React Router 7 n/a
nuxt3-starter-nodejs Nuxt 3 Vite 6 Node.js n/a
nuxt4-starter-nodejs Nuxt 4 Vite 7 Node.js n/a
bun None None Deno 2 n/a
deno None None Deno 2 n/a

[!WARNING] Deprecated

The prisma-client-js generator is deprecated. We recommend using prisma-client for new projects and updating existing projects when possible.

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

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

  • previewFeatures: Preview features to include
  • binaryTargets: Engine binary targets for prisma-client-js (for example, debian-openssl-1.1.x if you are deploying to Ubuntu 18+, or native if you are working locally)
prisma/schema.prisma
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["sample-preview-feature"]
  binaryTargets   = ["debian-openssl-1.1.x"] // defaults to `"native"`
}

[!NOTE] Existing generators or new ones should not be affected if you are using a multi-file Prisma schema, unless a generator reads the schema manually.

The following is a list of community created generators.

  • Data sources: Data sources enable Prisma to connect to your database. This page explains how to configure data sources in your Prisma schema
  • Schema location: Documentation regarding proper location of Prisma Schema including default naming and multiple files.
Suggest an edit

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

Export
Documentation menu