Skip to content

Conversation

cookieMonsterDev
Copy link

@cookieMonsterDev cookieMonsterDev commented Jul 19, 2025

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Docs
  • Other... Please describe:

What is the current behavior?

There is no documentation explaining how to set a custom Prisma client output path or how to ensure it's included in the NestJS build process.

Issue Number: N/A

What is the new behavior?

Adds documentation explaining:

  • How to configure a custom output path for the Prisma client.
  • How to ensure the generated client is included in the NestJS build by updating tsconfig.build.json

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@alifarooq-zk
Copy link

hey, do you have the full example. how to configure prisma using custom output path and new prisma-client which supports es-module without rust engine. i am talking about prisma v6.16.0

@cookieMonsterDev
Copy link
Author

cookieMonsterDev commented Sep 10, 2025

@alifarooq-zk It’s not like you need that many extra steps to configure it, at least according to the documentation.

So, I suppose the full code would look something like this:

  1. /prisma/schema.prisma
generator client {
  provider        = "prisma-client-js"
  output          = "../generated/prisma"
  engineType      = "client" 
}

model User {
  id      Int      @id @default(autoincrement())
  email   String   @unique
  name    String?
}
  1. src/database/database.service.ts
import { PrismaPg } from '@prisma/adapter-pg';
import { PrismaClient } from '@generated/prisma';
import { Injectable, OnModuleInit } from '@nestjs/common';

@Injectable()
export class DatabaseService extends PrismaClient implements OnModuleInit {
  constructor() {
    const adapter = new PrismaPg({ connectionString: process.env.POSTGRES_DATABASE_URL });
    super({ adapter });
  }

  async onModuleInit() {
    await this.$connect();
  }
}

@alifarooq-zk
Copy link

This one generates CommonJS (prisma-client-js), i wanted to use latest esm supported prisma (prisma-client) in NestJS. but it seems like NestJS does not support ESM.

@cookieMonsterDev
Copy link
Author

cookieMonsterDev commented Sep 11, 2025

@alifarooq-zk That is possible, but it will cause some trouble with custom paths if you are using them. Here is an example what you need to do:

  1. Update package.json to add type:
{
  "type": "module",
}  
  1. Update tsconfig.json to include next:
{
  "compilerOptions": {
     "module": "NodeNext",
     "moduleResolution": "NodeNext", 
     "resolveJsonModule": true,
     "esModuleInterop": true,
  },
}  
  1. Update schema.prisma, Note that importFileExtension should be js. With ts it wont work.
generator client {
  provider               = "prisma-client"
  output                 = "../generated/prisma"
  engineType             = "client"
  runtime                = "nodejs"
  moduleFormat           = "esm"
  generatedFileExtension = "ts"
  importFileExtension    = "js"
}
  1. Update imports. Note: Update imports. All imports in your code must now be relative, so this won't do ether: import { AppModule } from '@/app.module.js';
import { PrismaPg } from '@prisma/adapter-pg';
import { Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '../../generated/prisma/client.js';

@Injectable()
export class DatabaseService extends PrismaClient implements OnModuleInit {
  constructor() {
    const adapter = new PrismaPg({ connectionString: process.env.POSTGRES_DATABASE_URL });
    super({ adapter });
  }

  async onModuleInit() {
    await this.$connect();
  }
}

@cookieMonsterDev cookieMonsterDev changed the title docs(prisma-recipe): add note about custom Prisma client output path … docs(prisma-recipe): update docs for Prisma client output path and build config Sep 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants