Skip to content

Prisma Postgres Adapter with Turborepo does not work #27083

@SooditK

Description

@SooditK

Bug description

if I have a turborepo monorepo with a packages/db folder containing my prisma schema, and a apps/web application (Next.JS) and I use the updated prisma with previewFeatures = ["queryCompiler", "driverAdapters"]

I get an error:

web:dev: Error: ENOENT: no such file or directory, open '/MYPATH/MONOREPO/apps/web/generated/prisma/query_compiler_bg.wasm'
web:dev:     at Object.getQueryCompilerWasmModule (../../packages/db/generated/prisma/index.js:2534:70)
web:dev:     at eval (../../packages/db/generated/prisma/runtime/client.js:74:23092)
web:dev:   2532 |       getQueryCompilerWasmModule: async () => {
web:dev:   2533 |         const queryCompilerWasmFilePath = require('path').join(config.dirname, 'query_compiler_bg.wasm')
web:dev: > 2534 |         const queryCompilerWasmFileBytes = require('fs').readFileSync(queryCompilerWasmFilePath)
web:dev:        |                                                                      ^
web:dev:   2535 |
web:dev:   2536 |         return new WebAssembly.Module(queryCompilerWasmFileBytes)
web:dev:   2537 |       } {
web:dev:   errno: -2,
web:dev:   code: 'ENOENT',
web:dev:   syscall: 'open',
web:dev:   path: '/MYPATH/MONOREPO/apps/web/generated/prisma/query_compiler_bg.wasm'
web:dev: }

it is looking for query_compiler_bg.wasm at the web application but it should look for the same in the db package

before you ask if I am creating a new PrismaClient inside the web application, I'm not, I'm only creating one prisma client in db package and exporting it, which is getting used in all other apps

Severity

🚨 Critical: Data loss, app crash, security issue

Reproduction

Follow your guide to use prisma with turborepo and update the index.ts file to use the "Rust-free" version of Prisma ORM (using the queryCompiler and adapters), something you guys have mentioned here

Expected vs. Actual Behavior

let's call prisma with previewFeatures = ["queryCompiler", "driverAdapters"] to be p1
and
prisma without previewFeatures = ["queryCompiler", "driverAdapters"] to be p2

I expect p1 and p2 to behave the same when I'm using them in a monorepo/turborepo

Frequency

Consistently reproducible

Does this occur in development or production?

Both development and production

Is this a regression?

if I directly use prisma without the previewFeatures = ["queryCompiler", "driverAdapters"], it works

Workaround

as I said

if I directly use prisma without the previewFeatures = ["queryCompiler", "driverAdapters"], it works

Prisma Schema & Queries

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["queryCompiler", "driverAdapters", "views"]
  output          = "../generated/prisma"
}

generator kysely {
  provider     = "prisma-kysely"
  output       = "../src/db"
  fileName     = "types.ts"
  enumFileName = "enums.ts"
}

model AuthSession {
  id        String   @id @unique
  userId    String
  expiresAt DateTime @map("expiresAt")
 
  @@map("auth_session")
}
// and rest of the models
import { PrismaPg } from "@prisma/adapter-pg";
import * as dotenv from "dotenv";
import { Kysely, PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler } from "kysely";
import kyselyExtension from "prisma-extension-kysely";
import { PrismaClient as prismaClient } from "../generated/prisma";
import type { DB } from "./db/types";

import type { z } from "zod";
dotenv.config();

const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
const prismaBase = new prismaClient({ adapter });

const p = prismaBase.$extends(
	kyselyExtension({
		kysely: (driver) =>
			new Kysely<DB>({
				dialect: {
					createDriver: () => driver,
					createAdapter: () => new PostgresAdapter(),
					createIntrospector: (db) => new PostgresIntrospector(db),
					createQueryCompiler: () => new PostgresQueryCompiler(),
				},
				plugins: [],
			}),
	})
);

const globalForPrisma = global as unknown as { prisma: typeof p };

const prisma = globalForPrisma.prisma || p;

if (process.env.NODE_ENV !== "production") {
	globalForPrisma.prisma = prisma;
}

export { prisma };
type PrismaClient = typeof prisma;
export type { PrismaClient };

Prisma Config

I tried with and without it, the results were same

import "dotenv/config";
import path from "node:path";
import type { PrismaConfig } from "prisma";

export default {
	earlyAccess: true,
	schema: path.join("prisma", "schema.prisma"),
} satisfies PrismaConfig;

Logs & Debug Info

I was not able to run any database queries as it was throwing the following error everytime, so I have attached this only, let me know if you need anything else

web:dev: Error: ENOENT: no such file or directory, open '/MYPATH/MONOREPO/apps/web/generated/prisma/query_compiler_bg.wasm'
web:dev:     at Object.getQueryCompilerWasmModule (../../packages/db/generated/prisma/index.js:2534:70)
web:dev:     at eval (../../packages/db/generated/prisma/runtime/client.js:74:23092)
web:dev:   2532 |       getQueryCompilerWasmModule: async () => {
web:dev:   2533 |         const queryCompilerWasmFilePath = require('path').join(config.dirname, 'query_compiler_bg.wasm')
web:dev: > 2534 |         const queryCompilerWasmFileBytes = require('fs').readFileSync(queryCompilerWasmFilePath)
web:dev:        |                                                                      ^
web:dev:   2535 |
web:dev:   2536 |         return new WebAssembly.Module(queryCompilerWasmFileBytes)
web:dev:   2537 |       } {
web:dev:   errno: -2,
web:dev:   code: 'ENOENT',
web:dev:   syscall: 'open',
web:dev:   path: '/MYPATH/MONOREPO/apps/web/generated/prisma/query_compiler_bg.wasm'
web:dev: }

Environment & Setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: 20.11.1

Prisma Version

6.7.0
"@prisma/client": "^6.7.0",
"@prisma/adapter-pg": "^6.7.0"

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions