ReferenceError: __dirname is not defined in ES module scope

I am using Prisma Client with SvelteKit and I am getting this error on builds/preview. I have tried looking up solutions but I could not find a solution. I saw someone saying it should be fixed in Prisma 6.7. Is this true? This issue is preventing my application from working once it is built.
3 Replies
Prisma AI Help
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
Deleted User
Deleted UserOP2w ago
I have found a workaround to this. I replaced all occurrences of __dirname in the build directory with import.meta.url However, this is a bandaid solution and I would appreciate if there was an official way of fixing this.
Nurul
Nurul2w ago
Hey! Yes, this should be fixed in Prisma 6.7.0 https://github.com/prisma/prisma/pull/26892
GitHub
fix(client-generator-ts): don't use __dirname in class.ts in ES...
The __dirname shim was only built in client.ts but we had one more reference in class.ts which broke when building for ESM.

Did you find this page helpful?