FG
šŸ’» SoftwarešŸ—„ļø DatabasesVercel

Prisma Postgres Adapter with Turborepo does not work

Fresh3 days ago
Mar 14, 20260 views
Confidence Score71%
71%

Problem

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: [code block] 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 = ["q

Error Output

Error: ENOENT: no such file or directory, open '/MYPATH/MONOREPO/apps/web/generated/prisma/query_compiler_bg.wasm'

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix Prisma WASM File Path Issue in Turborepo Setup

Medium Risk

The error occurs because the Prisma client in the `web` application is looking for the `query_compiler_bg.wasm` file in its own directory instead of the `db` package where it is generated. This is due to the way the Prisma client is configured in a monorepo setup, leading to incorrect path resolution for the WASM file when using the `queryCompiler` preview feature.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Update Prisma Client Configuration

    Ensure that the Prisma client in the `db` package is correctly exporting the client with the necessary configurations. This includes setting the correct path for the WASM file.

    javascript
    const { PrismaClient } = require('@prisma/client');
    
    const prisma = new PrismaClient();
    
    module.exports = prisma;
  2. 2

    Set Environment Variable for WASM Path

    Set an environment variable in the `web` application to point to the correct location of the `query_compiler_bg.wasm` file in the `db` package. This can be done in the `.env` file or directly in the application code.

    javascript
    process.env.PRISMA_QUERY_COMPILER_WASM_PATH = '../db/generated/prisma/query_compiler_bg.wasm';
  3. 3

    Modify Next.js Configuration

    Update the Next.js configuration in the `web` application to ensure it correctly resolves the path to the WASM file during the build process.

    javascript
    const nextConfig = {
      webpack: (config) => {
        config.resolve.alias['@prisma/client'] = path.resolve(__dirname, '../db/node_modules/@prisma/client');
        return config;
      }
    };
    
    module.exports = nextConfig;
  4. 4

    Rebuild and Test the Application

    After making the above changes, rebuild the application and run it to confirm that the Prisma client is now able to locate the `query_compiler_bg.wasm` file correctly.

    bash
    npm run build && npm start

Validation

To confirm the fix worked, run the application and ensure that no errors related to the `query_compiler_bg.wasm` file are thrown. Additionally, verify that the Prisma client functions correctly with the `previewFeatures` enabled.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

prismaormpostgresqlbug/2-confirmedkind/bugtopic:-driveradapterstopic:-@prisma/adapter-pg