Cannot find module

Im working on a Nestjs Project with Prisma v7 Error: Cannot find module './generated/prisma/client' Require stack: - /Users/jack/Documents/Jedlabs Projects/fleet/apps/backend/dist/database/database.service.js - /Users/jack/Documents/Jedlabs Projects/fleet/apps/backend/dist/database/database.module.js - /Users/jack/Documents/Jedlabs Projects/fleet/apps/backend/dist/app.module.js - /Users/jack/Documents/Jedlabs Projects/fleet/apps/backend/dist/main.js
4 Replies
Prisma AI Help
Skipping coffee for instant knowledge! Let's brew that AI answer now. The error "Cannot find module './generated/prisma/client'" in your NestJS project with Prisma v7 is a common issue when using a custom Prisma Client output path. The root cause is that the generated Prisma Client directory is not copied to your build output (e.g., dist), so at runtime, Node.js cannot resolve the import. How to fix: 1. Include the generated folder as an asset in your build config.
If you use NestJS, update your nest-cli.json to copy the generated Prisma Client to your dist folder:
{
"$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
}
}

This ensures the generated client is available in your build output and can be imported at runtime NestJS: Error: Cannot find module './generated/client'. 2. Alternative: Use a copy script.
Add a script to your package.json to copy the generated files after build:
"copy:prisma": "cpx 'prisma/generated/**' 'dist/prisma/generated'"

"copy:prisma": "cpx 'prisma/generated/**' 'dist/prisma/generated'"

Then run this script after your build step NestJS: Error: Cannot find module './generated/client'. 3. Check your import paths.
Make sure your import path matches the generated output and the runtime location. For example, if you generate to src/generated/prisma, your import should be:
import { PrismaClient } from './generated/prisma/client';

import { PrismaClient } from './generated/prisma/client';

Summary:
You must ensure the generated Prisma Client directory is present in your build output. Adjust your build configuration or use a copy script to achieve this. This is a known issue when using custom output pa ths with Prisma and NestJS. 🤔 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.
Gregersen
Gregersen5d ago
Hey Jack, I updated the blog post referenced in another thread here on Prisma discord. I managed to create a minimal reproduction, maybe you can use this? https://mgregersen.dk/upgrading-prisma-to-rust-free-client-in-nestjs/
Martin Aarhus Gregersen
Martin Gregersen
Upgrading Prisma to Rust-free client in NestJS - Martin Gregersen
Updated 26.11 to reflect changes in Prisma version 7.0.0 In this article I’ll quickly go over the steps I took to update Prisma to the new rust free implementation, that is now “GA” as of Prisma version 6.16.0., as indicated by the recent blog on the topic: https://www.prisma.io/blog/rust-free-prisma-orm-is-ready-for-production. Prisma als...
Nurul
Nurul4d ago
Thank you so much for helping out 🙌 🙏
Gregersen
Gregersen3d ago
My pleasure, we're a community after all, aren't we 😄

Did you find this page helpful?