P
Prisma4w ago
begot

Issues with Prisma in Turborepo

I'm essentially generating the client and compiling a commonjs version so that i can use my Prisma client across our monorepo. this works, however, when i try to extend the client to use extensions, it breaks with the following error:
Error: Cannot find module '.prisma/client/default'
Error: Cannot find module '.prisma/client/default'
I've been at this for a day now, and I'm slowly losing my sanity with this. I don't understand why extending the client would break it. I tried looking for flags to include extensions in the generated client but couldn't find anything. The issue is that I need to use Prisma in both NextJS (EsNext) and NestJS (CommonJS) - which means I need both esm and cjs support for the exported clients.
No description
3 Replies
Prisma AI Help
You selected the carefully hand-crafted route. A dev artisan will respond soon. Meanwhile, the #ask-ai channel awaits if you're curious!
begot
begotOP4w ago
Without extending the client, it works as expected.
No description
begot
begotOP4w ago
I am willing to compromise as long as I can have a unified Prisma schema. Might be better to import the clients from @prisma/client in each app separately. But would this carry over the type safety? Would really appreciate some insight. I can provide repo access as well if needed. It seems moving extension exports from the shared @workspace/prisma package and manually importing from the extension packages solved the issue. I also had to modify my tsconfig.json for my NestJS project: Solution Approach Configuration Changes 1. Package Configuration (package.json for @workspace/prisma):
{
"name": "@workspace/prisma",
"exports": {
".": {
"require": "./index.cjs",
"import": "./index.ts",
"types": "./index.ts"
}
},
"scripts": {
"db:build": "swc ./index.ts -o ./index.cjs --quiet",
"db:generate": "prisma generate --no-hints",
"db:push": "prisma db push --skip-generate"
}
}
{
"name": "@workspace/prisma",
"exports": {
".": {
"require": "./index.cjs",
"import": "./index.ts",
"types": "./index.ts"
}
},
"scripts": {
"db:build": "swc ./index.ts -o ./index.cjs --quiet",
"db:generate": "prisma generate --no-hints",
"db:push": "prisma db push --skip-generate"
}
}
2. TypeScript Configuration (tsconfig.json for NestJS):
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Nest.js",
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"outDir": "./dist",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Nest.js",
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"outDir": "./dist",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
3. SWC Configuration (.swcrc):
{
"jsc": {
"parser": {
"syntax": "typescript",
"dynamicImport": true
},
"target": "es2022"
},
"module": {
"type": "commonjs"
}
}
{
"jsc": {
"parser": {
"syntax": "typescript",
"dynamicImport": true
},
"target": "es2022"
},
"module": {
"type": "commonjs"
}
}
Key Resolution Steps - Move extension exports from the shared package to individual app packages - Manually import from extension packages - Ensure separate client imports for each runtime environment Turborepo Configuration (turbo.json):
{
"db:build": {
"dependsOn": ["db:generate"],
"cache": false
},
"db:generate": {
"cache": false
}
}
{
"db:build": {
"dependsOn": ["db:generate"],
"cache": false
},
"db:generate": {
"cache": false
}
}
This approach allows for a unified Prisma schema while maintaining type safety and runtime compatibility across different project environments.

Did you find this page helpful?