Skip to content

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

Closed

Description

@pasha-vuiko

Bug description

If I'm trying to use Prisma Client with provider = "prisma-client" instead of provider = "prisma-client-js", I receive the following error:

path-to-project/dist/prisma/client/client.js:35
Object.defineProperty(exports, "__esModule", { value: true });
                      ^

ReferenceError: exports is not defined in ES module scope

In my project I use CommonJS, not ESM. Contents of my tsconfig.json:

{
  "compilerOptions": {
    "strict": true,
    "strictPropertyInitialization": false,
    "module": "nodenext",
    "moduleResolution": "nodenext",
    "noImplicitOverride": true,
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "target": "esnext",
    "lib": ["esnext"],
    "pretty": true,
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "types": ["vitest/globals"],
    "paths": {
      "@prisma-definitions/*": ["prisma/*"],
      "@api/*": ["src/api/*"],
      "@shared/*": ["src/shared/*"]
    }
  }
}

Possibly the reason is "moduleResolution": "nodenext", but I need dynamic imports in my project, so I cannot change it to something else

Severity

Not critical, I can change back to provider = "prisma-client-js"`, but still I would like to use the new version

Reproduction

Expected vs. Actual Behavior

Prisma Client with the provider = "prisma-client" works both for CommonJS and ESM

Frequency

Consistently reproducible

Does this occur in development or production?

Both development and production

Is this a regression?

I'm note sure, I just decided to use the new provider and faced the issue

Workaround

If I manually remove import.meta.url (a.k.a. ESM specific stuff) from the generated Prisma code, then it works

Prisma Schema & Queries

// Add relevant schema.prisma snippet
generator client {
  provider        = "prisma-client"
  previewFeatures = ["relationJoins", "driverAdapters", "metrics", "queryCompiler"]
  output          = "./client"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
// Add relevant Prisma Client query

Prisma Config

// Add your `prisma.config.ts`

N/A

Logs & Debug Info

// Debug logs here
path-to-project/dist/prisma/client/client.js:35
Object.defineProperty(exports, "__esModule", { value: true });
                      ^

ReferenceError: exports is not defined in ES module scope

Environment & Setup

  • OS: MacOS
  • Database: PostgreSQL
  • Node.js version: 22.17.0

Prisma Version

// Prisma version output

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
prisma : 6.10.1
@prisma/client : 6.10.1
Computed binaryTarget : darwin-arm64
Operating System : darwin
Architecture : arm64
Node.js : v22.17.0
TypeScript : 5.8.3
Query Compiler : enabled
PSL : @prisma/prisma-schema-wasm 6.10.1-1.9b628578b3b7cae625e8c927178f15a170e74a9c
Schema Engine : schema-engine-cli 9b628578b3b7cae625e8c927178f15a170e74a9c (at node_modules/@prisma/engines/schema-engine-darwin-arm64)
Default Engines Hash : 9b628578b3b7cae625e8c927178f15a170e74a9c
Studio : 0.511.0
Preview Features : driverAdapters, metrics, queryCompiler, relationJoins

Activity

  1. jkomyno commented on Jul 1, 2025

    @jkomyno
    Contributor

    Hey @pasha-vuiko,

    In my project I use CommonJS, not ESM

    Have you tried using moduleFormat = "cjs" (see docs)?

    generator client {
      provider = "prisma-client"
      output = "./client"
      previewFeatures = ["relationJoins", "driverAdapters", "metrics", "queryCompiler"]
      moduleFormat = "cjs"
    }
  2. pasha-vuiko commented on Jul 1, 2025

    @pasha-vuiko
    Author

    Heeey @jkomyno thank you so much it worked, I'm sorry, I did not know about the option

  3. yassineejjoud commented on Nov 5, 2025

    @yassineejjoud

    omg thank you it worked

  4. nndafnmain commented on Nov 11, 2025

    @nndafnmain

    Thanks it works!!

  5. zbouchlih commented on Nov 26, 2025

    @zbouchlih

    thank you so much @jkomyno

  6. tongge666 commented on Dec 15, 2025

    @tongge666

    Thanks it works!! Think you!!@jkomyno

  7. Rayan-Allali commented on Dec 29, 2025

    @Rayan-Allali

    thanks mate @jkomyno

  8. aNazirov commented on Mar 16, 2026

    @aNazirov

    Hey @pasha-vuiko,

    In my project I use CommonJS, not ESM

    Have you tried using moduleFormat = "cjs" (see docs)?

    generator client {
    provider = "prisma-client"
    output = "./client"
    previewFeatures = ["relationJoins", "driverAdapters", "metrics", "queryCompiler"]
    moduleFormat = "cjs"
    }

    Thanks, it works. moduleFormat = "cjs" was enough for my case

  9. guilhermealves18 commented on Mar 28, 2026

    @guilhermealves18

    moduleFormat = "cjs"

    Thanks, work for me too

  10. amiabl-programr commented on Mar 30, 2026

    @amiabl-programr

    moduleFormat = "cjs"

    It works for me too, thank you very much

  11. ReactorboY commented on Apr 12, 2026

    @ReactorboY

    It works, thank you very much.
    NOTE: Please delete old generated PrismaClient and regenerate then it will work

  12. shaishab316 commented on Aug 29, 2026

    @shaishab316

    Hey @pasha-vuiko,

    In my project I use CommonJS, not ESM

    Have you tried using moduleFormat = "cjs" (see docs)?

    generator client {
    provider = "prisma-client"
    output = "./client"
    previewFeatures = ["relationJoins", "driverAdapters", "metrics", "queryCompiler"]
    moduleFormat = "cjs"
    }

    Thank you,

    [7:57:53 AM] File change detected. Starting incremental compilation...

    [7:58:03 AM] Found 0 errors. Watching for file changes.

    file:///C:/Users/Incognito/Projects/lumiphoto/dist/generated/prisma/client.js:38
    Object.defineProperty(exports, "__esModule", { value: true });
    ^

    ReferenceError: exports is not defined in ES module scope
    at file:///C:/Users/Incognito/Projects/lumiphoto/dist/generated/prisma/client.js:38:23
    at ModuleJobSync.runSync (node:internal/modules/esm/module_job:517:37)
    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:388:47)
    at loadESMFromCJS (node:internal/modules/cjs/loader:1578:24)
    at Module._compile (node:internal/modules/cjs/loader:1743:5)
    at Object..js (node:internal/modules/cjs/loader:1893:10)
    at Module.load (node:internal/modules/cjs/loader:1481:32)
    at Module._load (node:internal/modules/cjs/loader:1300:12)
    at TracingChannel.traceSync (node:diagnostics_channel:328:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:245:24)

    Node.js v24.12.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions