Cannot find module '../../../generated/prisma/index.js' in NestJs
I’m working on a NestJS project where the Prisma Client is generated into a custom output directory using this generator config.
version "@prisma/client": "^7.0.0",
15 Replies
You've gone full bot mode! Let me fetch that AI answer for you ASAP.
The error "Cannot find module '../../../generated/prisma/index.js'" in your NestJS project is a common issue when using a custom Prisma Client output path. The root cause is that NestJS's build process (TypeScript compilation) does not automatically copy non-TypeScript files (like your generated Prisma Client) into the dist directory. As a result, at runtime, the compiled code cannot find the generated client module.
Solution:
You need to explicitly tell NestJS to copy the generated Prisma Client files to the dist folder during the build. This is done by updating your
You need to explicitly tell NestJS to copy the generated Prisma Client files to the dist folder during the build. This is done by updating your
nest-cli.json to include the generated folder as an asset:
Adjust the include and outDir paths to match your project structure. This ensures the generated Prisma Client is available in the dist folder after building, resolving the module not found error. This approach is confirmed to work by multiple users in the Prisma community and is the recommended workaround for this scenario NestJS: Error: Cannot find module './generated/client'.
Alternatively, you can use a script (e.g., with cpx) to copy the generated files after build, but updating nest-cli.json is the most straightforward and robust solution.nah the error is still there
🤔 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.
What does your Prisma Service look like?

Thats not correct per the documentation. I actually have a blog post in which I've documented all of the upgrade for myself, so I could remember, I think it might be helpful:
https://mgregersen.dk/upgrading-prisma-to-rust-free-client-in-nestjs/
I notice at least that the service doesnt look correct, and you may need to setup a config file and remember to run the generate script too 🙂
Let me know if it works out for you
Martin Aarhus Gregersen
Martin Gregersen
Upgrading Prisma to Rust-free client in NestJS - Martin Gregersen
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 Updating and configuring Prisma First things first, first we need to...
Thanks for the blog post! Do you have a GitHub repo for this setup as well? 🙏
I did what was wrotten in the blog post, but im still facing the same error: file:///Users/jack/Documents/Jedlabs%20Projects/fleet/apps/backend/dist/src/database/generated/client.js:38
Object.defineProperty(exports, "__esModule", { value: true });
^
ReferenceError: exports is not defined in ES module scope
at file:///Users/jack/Documents/Jedlabs%20Projects/fleet/apps/backend/dist/src/database/generated/client.js:38:23
Did it work for you?
no
I dont, but I suppose I could set one up.
Sorry to hear it didnt work for you both! Seems I have some updating to do.
Have you ran the
prisma generate command?if you could please set one up on GitHub, I’d really appreciate it so I can take a look at it as an example.
yess i do ran the prisma generate command.
I'm taking a look at setting a sample repo up now 🙂
I've updated the blog post to verify that everything is setup.
From the error you are describing @Jack Delamou are you using esm?
I dont think NestJs supports that yet.
https://github.com/aarhusgregersen/prisma7-nestjs-template
Here's a minimal reproduction @lyhourrrr , hopefully you can use this 🙂
This builds and runs no problem.
GitHub
GitHub - aarhusgregersen/prisma7-nestjs-template: Documents how Pri...
Documents how Prisma version 7.0.0 can be configured with NestJS - aarhusgregersen/prisma7-nestjs-template
Thanks so much,I tried it and it works perfectly. Really appreciate your help 🙏
No problem at all, happy I could help 🙂 Happy coding! 👏