4

Prisma works locally and I can invoke my server actions without any problem. However, when I deploy, I get


`Unhandled Rejection: Error [PrismaClientInitializationError]: Prisma Client could not locate the Query Engine for runtime "rhel-openssl-3.0.x".

We detected that you are using Next.js, learn how to fix this: https://pris.ly/d/engine-not-found-nextjs.

This is likely caused by a bundler that has not copied "libquery_engine-rhel-openssl-3.0.x.so.node" next to the resulting bundle.
Ensure that "libquery_engine-rhel-openssl-3.0.x.so.node" has been copied next to the bundle or in "generated/prisma".

We would appreciate if you could take the time to share some information with us.
Please help us by answering a few questions: https://pris.ly/engine-not-found-bundler-investigation

The following locations have been searched:
  /var/task/generated/prisma
  /var/task/.next/server
  /vercel/path0/generated/prisma
  /var/task/.prisma/client
  /tmp/prisma-engines
    at yl (.next/server/chunks/546.js:64:756)
    at async Object.loadLibrary (.next/server/chunks/546.js:111:10410)
    at async Gr.loadEngine (.next/server/chunks/546.js:112:448)
    at async Gr.instantiateLibrary (.next/server/chunks/546.js:111:13913) {
  clientVersion: '6.6.0',
  errorCode: undefined
}
Node.js process exited with exit status: 128. The logs above can help with debugging the issue.` error. generator client {
  provider = "prisma-client-js"
  output   = "../generated/prisma"
}
datasource db {
  provider  = "postgresql"
  url       = env("DATABASE_URL")
  directUrl = env("DIRECT_URL")
}

this is my schema.prisma set up and


    "scripts": {
        "dev": "next dev",
        "build": "prisma generate && next build",
        "start": "next start",
        "lint": "next lint"
      },
      "prisma": {
        "seed": "ts-node --compiler-options {\"module\":\"commonjs\"} prisma/seed.ts"
      }

and i am using prisma 6.6.0 in nextjs 15.3.1. I am deploying it to vercel and it builds without any problem.

import { PrismaClient } from "../../generated/prisma";

const globalForPrisma = global as unknown as {
  prisma: PrismaClient;
};

const prisma = globalForPrisma.prisma || new PrismaClient();

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

export default prisma;

this is how i initialize prisma client.

0

3 Answers 3

4

i want to add the working approach. above comment also a working approach. but it was not described enough with resources.

so, here it goes. in my case, this is how i solved vercel prisma rhel issue.

  • prisma version 6.7.0 (6.6.0 may works too)
  • you can not use new prisma client generator (prisma-client)

here i provide all the code step by step.

in schema.prisma

generator client {
  provider      = "prisma-client-js" // here do not use the new client (prisma-client)
  binaryTargets = ["native", "linux-musl", "rhel-openssl-3.0.x"]  // first one is for cross-platform, second one for docker, last one for serverless environment. safe to include all
  output        = "../src/generated/client" // it is better to include the generator inside `src/` or `app/` if `src/` not available.
}

install this package. go to npm repo and update next.config.mjs like above docs. but here is my full code of next.config.mjs

import { PrismaPlugin } from "@prisma/nextjs-monorepo-workaround-plugin";

/** @type {import('next').NextConfig} */
const nextConfig = {
    devIndicators: false,
    experimental: {
        authInterrupts: true,
    },
    webpack: (config, { isServer }) => {
        if (isServer) {
            config.plugins = [...config.plugins, new PrismaPlugin()];
        }
        return config;
    },
};

export default nextConfig;

then run bunx prisma generate or npx prisma generate

my package.json scripts used on vercel build

"scripts": {
    "dev": "next dev --turbopack",
    "vercel-build": "bunx prisma generate && bun run build",
    "build": "next build",
    "postinstall": "bunx prisma generate"
  }

then vercel build command was bun run vercel-build

Sign up to request clarification or add additional context in comments.

Comments

0

I made some progress. So I created another page at /prisma-check and it has

import prisma from "@/lib/prisma";
import React from "react";

const PrismaCheckPage = async () => {
  const user = await prisma.user.findMany();
  return (
    <div>
      <h1 className="text-3xl font-bold">Prisma Check</h1>
      <p className="text-lg">User Count: {user.length}</p>
      <ul className="list-disc pl-5">
        {user.map((u) => (
          <li key={u.id}>{u.email}</li>
        ))}
      </ul>
    </div>
  );
};

export default PrismaCheckPage;

and suddenly it works. But without this page, the form at the /contact route does not work

export async function addContactFormToDB(
  values: z.infer<typeof contactFormSchema>
) {
  try {
    // --- Rate Limiting Check ---
    const ip = await getIP(); // Get the user's IP address
    const rateLimitResult = await rateLimitContact(ip);

    if (!rateLimitResult.success) {
      return rateLimitResult; // Return the rate limit error message
    }
    // --- End Rate Limiting Check ---

    // Proceed with validation and database operation if rate limit not exceeded
    const zodResult = contactFormSchema.safeParse(values);
    if (!zodResult.success) {
      // Log validation errors for debugging if needed
      console.error("Form validation failed:", zodResult.error.flatten());
      return {
        success: false,
        // It's often better to give a generic message unless you map errors
        message: "Invalid form data. Please check your entries.",
      };
    }

    // Use the validated data from zodResult.data
    const validatedData = zodResult.data;

    await prisma.contactForm.create({
      data: {
        name: validatedData.name,
        email: validatedData.email,
        phoneNumber: validatedData.phone ?? "", // Ensure 'phone' exists in your validated data
        message: validatedData.message,
      },
    });
    return {
      success: true,
      message: "We've received your request and will get back to you soon.",
    };
  } catch (error) {
    // Log the actual error on the server for debugging
    console.error("Contact form submission error:", error);

    // Return a generic error message to the client
    return {
      success: false,
      message:
        "Failed to submit the form due to a server error. Please try again later.",
    };
  }
}

this is contact form submission action that does not work without the prisma check page. I have no idea why it is resulting in an error without prisma check page, and works with the prisma check page that has no relation to the action whatsoever.

1 Comment

Solved it by adding ``` webpack: (config, { isServer }) => { if (isServer) { config.plugins = [...config.plugins, new PrismaPlugin()]; } return config; } ``` to my next config and ``` generator client { provider = "prisma-client-js" output = "../generated/prisma" binaryTargets = ["native", "rhel-openssl-3.0.x"] ##Added line } ```
0

I was trying to deploy a monorepo to Vercel, I got this error. I tried adding

binaryTargets = ["native", "linux-musl", "rhel-openssl-3.0.x"]

in the generator section of the prisma schema file but no luck.

Here's what worked for me: https://www.answeroverflow.com/m/1366677484229230622

It involves using the @prisma/nextjs-monorepo-workaround-plugin package.

I ran cd apps/web then i ran pnpm install @prisma/nextjs-monorepo-workaround-plugin then when it was done, i edited my next.config.mjs file.

Here's my next.config.mjs file:

import { PrismaPlugin } from '@prisma/nextjs-monorepo-workaround-plugin'
/** @type {import('next').NextConfig} */

const nextConfig = {
  transpilePackages: ["@workspace/ui"],
  webpack: (config, { isServer }) => {
    if (isServer) {
      config.plugins = [...config.plugins, new PrismaPlugin()]
    }
    return config
  },
}

export default nextConfig

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.