Skip to content
← Back to activity

Public problem

ReferenceError: exports is not defined in ES module scope with provider = "prisma-client"

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

When switching the generator provider from "prisma-client-js" to the new "prisma-client" in a CommonJS project (moduleResolution: "nodenext"), the generated client crashes at startup: Object.defineProperty(exports, "__esModule", { value: true }) throws ReferenceError: exports is not defined in ES module scope. The generator emits ESM output by default, which breaks under a CommonJS runtime even though the project itself is not ESM.

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

Add moduleFormat = "cjs" to your generator block:

generator client { provider = "prisma-client" output = "./client" moduleFormat = "cjs" }

Then delete the old generated output and re-run prisma generate. The reporter and several later commenters confirmed this fixes the crash immediately. The generator defaults to ESM output, so any CommonJS project using the new "prisma-client" provider needs this line. Source: https://github.com/prisma/prisma/issues/27556