You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prisma Client 7 generated code breaks when bundling with Webpack (ESM .js import issue) #28627
When using provider = "prisma-client" in Prisma 7 with a custom output path (e.g. ./prisma-generated), Prisma generates TypeScript files such as client.ts that contain imports like:
import { PrismaClientClass } from "./internal/class.js";
However, only class.ts exists, not class.js.
When bundling with Webpack (NestJS), this results in module resolution errors:
Module not found: Error: Can't resolve './internal/class.js'
Why this happens
• Prisma 7 generates ESM-style .js imports in TypeScript files
• These files do not exist yet at build time (class.ts exists, not class.js)
• Webpack does not resolve .js → .ts automatically ?
⸻
This issue causes bundling failures in real-world setups (NestJS monorepos).
It would be helpful if Prisma Client generated TS-friendly import paths or documented this behavior.
Tech Version
Prisma 7.0.0
Node 24.11.1
TS 5.9.x
Runtime Node
PackageMnager Bun
Bundler Webpack (NestJS)
OS macOS ARM64
Reacted by linhtrinh18, Artur Papa, Alexander Arrico, James-Souza, Onur Özkan, Jakub T. Jankiewicz, Michael, Mathieu REHO, Antomur, Lutfi Fajar and 10 more
I'm facing the same error I'm stuck in my project cause I cant access the prisma client correctly and then my project can't be compiled, I'm using Windows 11, but I tested on a Mac and got the same issue. I tried to generate the client with the output path and without the path, referencing '@prisma/client' and referencing the generated folder and none of this helped.
make sure that you're always importing PrismaClient from the generated folder (defined via the output attribute in schema.prisma's generator block), and not from @prisma/client
make sure that you're always importing PrismaClient from the generated folder (defined via the output attribute in schema.prisma's generator block), and not from @prisma/client
Thanks!
Thank you for your response, I have just updated the issue.
1- Remove "type": "module" from the package.json (even though the Prisma 7 documentation recommends keeping it).
2- Create a webpack.config.cjs file with:
1- Remove "type": "module" from the package.json (even though the Prisma 7 documentation recommends keeping it). 2- Create a webpack.config.cjs file with:
Adding my experience with this issue on a self-hosted Windows Server setup.
Environment:
Next.js 16.2.1 with webpack (not Turbopack)
Prisma 7.5.0 with @prisma/adapter-mariadb (MySQL 9.5.0)
Windows Server 2025, IIS Reverse Proxy, deployed via Task Scheduler
Node.js 22.x, ESM ("type": "module")
What happened:
After a full migration from Prisma 6 to 7 (including prisma-client generator, prisma.config.ts, driver adapter, all import paths updated), the build succeeded locally on Linux without any errors (typecheck, lint, build all clean).
On the Windows Server, the site started throwing intermittent 502 Bad Gateway errors — but neither Next.js nor IIS logged any error messages. The failure was completely silent. Some pages worked fine (static/cached), while pages requiring database access would fail.
import.meta.url is undefined in webpack server bundles, causing:
TypeError: The URL must be of scheme file
Why this was hard to diagnose:
The crash happens during module loading, before Next.js can handle or log the error. IIS only sees "backend not responding" and returns 502. It took a full server restart to force the bundler to re-initialize all modules, which finally surfaced the actual database connection errors that pointed to Prisma.
Workaround attempted:
I wrote a post-generate patch script replacing the hard fileURLToPath(import.meta.url) call with a fallback chain (import.meta.url → __dirname → process.cwd()). This worked on Linux but still caused issues on the Windows Server environment.
Resolution:
Reverted to Prisma 6.19.2. Everything works again immediately.
This is a blocker for self-hosted webpack deployments. The silent failure mode makes it especially dangerous — there's no indication that Prisma is the cause until you happen to trigger a full re-initialization.
Activity
linhtrinh18 commentedon Nov 21, 2025
Facing the same error.
PapaArt commentedon Nov 21, 2025
I'm facing the same error I'm stuck in my project cause I cant access the prisma client correctly and then my project can't be compiled, I'm using Windows 11, but I tested on a Mac and got the same issue. I tried to generate the client with the output path and without the path, referencing '@prisma/client' and referencing the generated folder and none of this helped.
fruitsdrink commentedon Nov 22, 2025
Facing the same error.
aniketicloud commentedon Nov 22, 2025
Facing the same error. I'm using prisma in next js project
piotrberlowski commentedon Nov 22, 2025
Workaround:
This changes the "file extension used in import statements" to empty.
jcubic commentedon Nov 22, 2025
importFileExtension = ""doesn't work for me. I tested every option (proabbly).piotrberlowski commentedon Nov 22, 2025
Does the generator ignore this option for you and still generate import statements with file extension then?
jcubic commentedon Nov 23, 2025
@piotrberlowski this is what I've meant by "not working"
linhtrinh18 commentedon Nov 24, 2025
Avoid using the "@prisma/client" in any type of server components, as it will fail when it comes to build/compile the project.
jkomyno commentedon Nov 24, 2025
Hi @AnthonyGhizzo and others, please always provide a minimal reproduction, otherwise we won't be able to investigate the problem you're facing.
In the meantime:
prisma-client-jsgenerator that there is no possible one-size-fit-all scenario)PrismaClientfrom the generated folder (defined via theoutputattribute inschema.prisma's generator block), and not from@prisma/clientThanks!
jcubic commentedon Nov 24, 2025
@jkomyno Will try to create a minimal example with Next.js that I use. In the meantime, I can share my project if you want.
AnthonyGhizzo commentedon Nov 24, 2025
Thank you for your response, I have just updated the issue.
jcubic commentedon Nov 24, 2025
@AnthonyGhizzo Minimal reproduction is code that you can run, that isolate the issue and have minimal amount of code. See Wikipedia: Minimal reproducible example
AnthonyGhizzo commentedon Nov 25, 2025
A temporary solution I found is:
1- Remove
"type": "module"from the package.json (even though the Prisma 7 documentation recommends keeping it).2- Create a webpack.config.cjs file with:
3- (In my case, I’m using a NestJS environment)
Update the nest-cli.json file with:
After applying these changes, the project compiles successfully.
jcubic commentedon Nov 25, 2025
The workaround doesn't work in Next.js. I've tried to customize Webpack via Next config:
and got same error
sohaibkhalid-dev commentedon Nov 28, 2025
You don't need to do this. try the official way
https://docs.nestjs.com/recipes/prisma
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
moduleFormat = "cjs"
}
You just need to add moduleFormat.
wppaing commentedon Nov 29, 2025
bump
jcubic commentedon Nov 29, 2025
This solves the problem on my end:
Found in this issue:
devanshtakkar commentedon Dec 13, 2025
This actually solved the issue. Thank you
BonaparteIT commentedon Jan 1, 2026
this works for my stack NestJS + Prisma 7.2.0
ahmed8mansour commentedon Jan 6, 2026
finally , this solves the issue , thanks
mdtausifiqbal commentedon Jan 17, 2026
@AnthonyGhizzo To solve this error, I changed generator setting and run
prisma generatecommand this fixed my errorDjurdjijan commentedon Jan 26, 2026
The only working solution in Nest.js is this:
add this to your webpack.config.js with
Update nest.cli.json as well:
schema.prisma example
PrismaService.ts Example
QuDaMyker commentedon Mar 21, 2026
Love you so much, f*cking example Prisma Nestjs not working
JonKazama-Hellion commentedon Mar 27, 2026
Adding my experience with this issue on a self-hosted Windows Server setup.
Environment:
@prisma/adapter-mariadb(MySQL 9.5.0)"type": "module")What happened:
After a full migration from Prisma 6 to 7 (including
prisma-clientgenerator,prisma.config.ts, driver adapter, all import paths updated), the build succeeded locally on Linux without any errors (typecheck,lint,buildall clean).On the Windows Server, the site started throwing intermittent 502 Bad Gateway errors — but neither Next.js nor IIS logged any error messages. The failure was completely silent. Some pages worked fine (static/cached), while pages requiring database access would fail.
The root cause is the generated
client.ts:import.meta.urlis undefined in webpack server bundles, causing:Why this was hard to diagnose:
The crash happens during module loading, before Next.js can handle or log the error. IIS only sees "backend not responding" and returns 502. It took a full server restart to force the bundler to re-initialize all modules, which finally surfaced the actual database connection errors that pointed to Prisma.
Workaround attempted:
I wrote a post-generate patch script replacing the hard
fileURLToPath(import.meta.url)call with a fallback chain (import.meta.url→__dirname→process.cwd()). This worked on Linux but still caused issues on the Windows Server environment.Resolution:
Reverted to Prisma 6.19.2. Everything works again immediately.
This is a blocker for self-hosted webpack deployments. The silent failure mode makes it especially dangerous — there's no indication that Prisma is the cause until you happen to trigger a full re-initialization.
Fix broken imports from Prisma 7 custom generated client