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 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
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:
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.
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:
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:
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.
[!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.
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)
[!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.
prisma-json-types-generator: Enhances prisma-client-js (or prisma-client) to provide strongly typed JSON fields for all databases, based on your schema. It improves code generation, Intellisense, and more, without affecting runtime code.
prisma-typegraphql-types-gen: Generates TypeGraphQL class types and enums from your prisma type definitions, the generated output can be edited without being overwritten by the next gen and has the ability to correct you when you mess up the types with your edits.
prisma-kysely: Generates type definitions for Kysely, a TypeScript SQL query builder. This can be useful to perform queries against your database from an edge runtime, or to write more complex SQL queries not possible in Prisma without dropping type safety.
prisma-generator-plantuml-erd: Generator to generate ER diagrams for PlantUML. Markdown and Asciidoc documents can also be generated by activating the option.
prisma-class-generator: Generates classes from your Prisma Schema that can be used as DTO, Swagger Response, TypeGraphQL and so on.
zod-prisma: Creates Zod schemas from your Prisma models.
prisma-pothos-types: Makes it easier to define Prisma-based object types, and helps solve n+1 queries for relations. It also has integrations for the Relay plugin to make defining nodes and connections easy and efficient.
prisma-generator-pothos-codegen: Auto generate input types (for use as args) and auto generate decoupled type-safe base files makes it easy to create customizable objects, queries and mutations for Pothos from Prisma schema. Optionally generate all crud at once from the base files.
prisma-markdown: Generates markdown document composed with ERD diagrams and their descriptions. Supports pagination of ERD diagrams through @namespace comment tag.
prisma-models-graph: Generates a bi-directional models graph for schema without strict relationship defined in the schema, works via a custom schema annotation.
prisma-generator-fake-data: Generates realistic-looking fake data for your Prisma models that can be used in unit/integration tests, demos, and more.