Skip to content

clientPath incompatible with Prisma 7's prisma-client generator (TypeScript output) #22

@tywenk

Description

@tywenk

⚠️ 🤖 Fair warning, I had Claude Code write up this following bug report, but it accurately reflects my experience trying to integrate this package into a greenfield product.


This package uses createRequire() to load the Prisma client at runtime:

// src/context.ts from the bundled node_modules
var require2 = createRequire(import.meta.url);
const { PrismaClient } = require2(options.clientPath);

This is incompatible with Prisma 7's new prisma-client generator, which outputs TypeScript files instead of compiled JavaScript. Node.js require() cannot load .ts files natively.

Steps to Reproduce

  1. Use Prisma 7 with the new prisma-client generator:
generator client {
  provider = "prisma-client"
  output   = "../lib/generated/prisma"
}
  1. Configure vitest with the environment:
environmentOptions: {
  "prisma-postgres": {
    clientPath: "./lib/generated/prisma/client.ts",
    // or with absolute path
    clientPath: path.resolve(__dirname, "lib/generated/prisma/client.ts"),
  },
},
  1. Run tests

Expected Behavior

The Prisma client should load successfully.

Actual Behavior

Error: Cannot find module './lib/generated/prisma/client.ts'

Or if using an absolute path:

Error: Cannot find module '/path/to/lib/generated/prisma/enums'
imported from /path/to/lib/generated/prisma/client.ts

The second error occurs because the TypeScript file uses extensionless imports (import * from "./enums") which ESM resolution cannot resolve.

Environment

  • vitest-environment-prisma-postgres: 1.0.1
  • Prisma: 7.2.0
  • Vitest: 4.0.17
  • Node.js: 24.x

Workaround

Add the legacy prisma-client-js generator alongside the new one:

generator client {
  provider = "prisma-client"
  output   = "../lib/generated/prisma"
}

generator clientJs {
  provider = "prisma-client-js"
}

Then use clientPath: "@prisma/client" in the vitest config.

Suggested Fix

Consider using dynamic import() instead of require() to load the client, which would allow Vitest's module transformation to handle TypeScript files. Alternatively, document the Prisma 7 incompatibility and the workaround.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions