-
-
Notifications
You must be signed in to change notification settings - Fork 3
Description
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
- Use Prisma 7 with the new prisma-client generator:
generator client {
provider = "prisma-client"
output = "../lib/generated/prisma"
}
- 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"),
},
},
- 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.