P
Prisma•2mo ago
lyhourrrr

Prisma + NestJS import issue when using custom client output

When using a custom Prisma Client output directory inside a NestJS project, the generated client cannot be imported correctly — even though the files exist and Prisma successfully generates them. Error: Cannot find module '../../../prisma/generated/prisma' Require stack: - dist/src/libs/prisma/prisma.service.js - dist/src/libs/prisma/prisma.module.js - dist/src/app.module.js - dist/src/main.js version: "prisma": "^6.17.1",
No description
No description
2 Replies
Prisma AI Help
Prisma AI Help•2mo ago
You selected the bot's instantaneous insights. Let me compile your answer right away! This is a common issue when using custom Prisma Client output paths in NestJS. The generated client files exist but aren't being copied to the dist folder during the build process. Solutions 1. Configure NestJS to Copy Generated Files Modify your nest-cli.json to include the generated folder as assets:
{
"$schema": "<https://json.schemastore.org/nest-cli",>
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"assets": [
{
"include": "../prisma/generated",
"outDir": "dist/prisma",
"watchAssets": true
}
],
"watchAssets": true
}
}
{
"$schema": "<https://json.schemastore.org/nest-cli",>
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"assets": [
{
"include": "../prisma/generated",
"outDir": "dist/prisma",
"watchAssets": true
}
],
"watchAssets": true
}
}
Adjust the include path based on where your generated client is located relative to your source root. NestJS custom output path issue 2. Exclude Prisma Folder from Build If you have a seed.ts file in your prisma folder, it can affect the dist structure. Exclude it in tsconfig.build.json:
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts", "prisma"]
}
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts", "prisma"]
}
Seed file issue 3. Alternative: Generate Outside Prisma Folder Generate the client outside the prisma directory or at the project root, which gets picked up more reliably by NestJS bundlers. Output path location Important Note When using custom output, you must import from the generated path, not from @prisma/client:
import { PrismaClient } from '../../../prisma/generated/prisma';
import { PrismaClient } from '../../../prisma/generated/prisma';
Custom output import requirement šŸ¤” Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Nurul
Nurul•4w ago
How have you aliased generated? What happens if you try importing from ../../generated/prisma in prisma.service.ts?

Did you find this page helpful?