05/12/2026

Prisma's Query Engine Goes Missing in Next.js Standalone Builds: Here's Why and How to Fix It

Knowledge_seci_model

You add output: 'standalone' to next.config.js, build your Docker image, and everything works on your laptop. You push it to production, the container starts, a request hits an API route that touches your database, and the process throws:

PrismaClientInitializationError:
Invalid `prisma.user.findMany()` invocation:
Could not locate the Query Engine for runtime "linux-musl-openssl-3.0.x".

Locally it was darwin or linux-x64. In the container it's a different target entirely, and the file genuinely isn't there. This is a packaging gap between how Next.js traces your dependencies for a standalone build and how Prisma ships a platform-specific native binary — and it only shows up once you're running on infrastructure that differs from your dev machine.

Why standalone output doesn't see Prisma's binary

output: 'standalone' works by statically analyzing your code with @vercel/nft (Node File Trace) and copying only the files it can prove are actually required into .next/standalone. That's how a Next.js production image can weigh tens of megabytes instead of hundreds — it skips the rest of node_modules.

The trace works well for JavaScript imports. It does not reliably work for Prisma's query engine, because that engine isn't a JS file your code require()s directly — it's a binary selected at prisma generate time based on binaryTargets, then loaded by the Prisma Client through a resolver that picks the right file for the current platform. NFT has no static import to follow, so depending on your Prisma version and your Dockerfile's copy step, the engine binary for the container's actual platform can be left out of .next/standalone/node_modules/.prisma/client.

The failure only appears at runtime, inside the container, on the exact OS/libc combination you deploy to. A build that reports "Compiled successfully" has told you nothing about whether the engine is present, because tracing and packaging happen at build time, and the client only tries to load the engine file when a query runs.

Confirming it's a binary problem, not a connection problem

The error message names the runtime it expected (linux-musl-openssl-3.0.x is what you'll see most often, because Alpine-based Node images use musl libc instead of glibc). Before changing anything, confirm the binary is simply absent:

docker run --rm -it your-image:latest sh
find / -iname "*query-engine*" 2>/dev/null
find / -iname "*libquery_engine*" 2>/dev/null

If that returns nothing in the deployed container but something does exist for a different target under node_modules/.prisma/client in your build context, the trace dropped the right file — this isn't a database connectivity issue, a missing DATABASE_URL, or a schema mismatch. Those produce different error classes (PrismaClientKnownRequestError, connection timeouts). PrismaClientInitializationError naming a specific runtime target is specifically about the engine file.

Fix 1: Tell Prisma which binary targets to generate

Prisma's binary engine documentation covers binaryTargets in the generator block. If your build machine and your runtime container use different libc implementations — a common case when you build on a Debian-based CI image but run on node:20-alpine — add both targets explicitly:

generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "linux-musl-openssl-3.0.x"]
}

"native" keeps the engine for wherever prisma generate actually runs (useful for local development and tests); the second entry adds the one your container needs. Run prisma generate again after this change — it has to regenerate the client with the new target list before a build can pick it up. Match the OpenSSL suffix to your base image; Prisma's engine naming is tied to the OpenSSL version available in that image, and a mismatch produces the same error with a different runtime string.

Fix 2: Copy the Prisma engine into the standalone output explicitly

binaryTargets solves generation. It doesn't guarantee the file survives Next.js's trace-and-copy step into .next/standalone. The dependable fix is to stop relying on the trace for this one dependency and copy it yourself, after the Next.js build, in your Dockerfile:

FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npx prisma generate
RUN npm run build

FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production

COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public

COPY --from=builder /app/node_modules/.prisma/client ./node_modules/.prisma/client
COPY --from=builder /app/node_modules/@prisma/client ./node_modules/@prisma/client

EXPOSE 3000
CMD ["node", "server.js"]

This is the step most "it compiled, so it should work" deployments skip, and why the error only surfaces once the image actually runs. The two COPY lines for .prisma/client and @prisma/client are the part the standalone trace misses — treat them as mandatory whenever you combine output: 'standalone' with Prisma, and add them before you ever see the error, not after.

Fix 3: Run the query engine as a separate binary target, not through the trace at all

If you're on a setup where the above still doesn't resolve it — monorepos with a custom outputFileTracingRoot are the usual offender, since the trace root changes which node_modules tree gets scanned — Prisma's Driver Adapters let you query through a database driver (@prisma/adapter-pg, @prisma/adapter-planetscale, and others) instead of the native query engine binary at all. This removes the binary-location problem entirely for supported databases, at the cost of adopting a newer, still-evolving part of the Prisma API. For most standalone + Docker deployments, Fix 1 and Fix 2 together are enough; reach for this only if the engine still won't load after confirming both.

None of this is specific to this one error

The underlying issue — Next.js's dependency tracer not seeing a native binary your app actually loads at runtime — comes up with other native dependencies too: sharp for image processing, bcrypt, native Puppeteer/Chromium downloads. Prisma's query engine just happens to be the one most self-hosted teams hit first, because output: 'standalone' and Prisma's ORM are both default recommendations for a production Next.js stack.

Before and after diagram: standalone trace excluding Prisma's engine file, then an explicit Dockerfile copy step including it

If you're already past this and the container builds and runs cleanly, the next failure mode usually isn't the application anymore — it's the cluster underneath it. A single container running fine on your machine doesn't tell you how it behaves restarting, scaling, or failing over in production, which is a different set of problems than what runs inside the image. If you're choosing or re-evaluating a Kubernetes distribution to run that container on, K3s vs K8s lays out where a lighter distribution is a straightforward win and where it isn't.

Automating the rebuild so this doesn't come back

Once the Dockerfile is correct, the easy way to reintroduce this bug is a CI pipeline that doesn't rebuild the image the same way every time — a cached layer that skips the prisma generate step, or a pipeline that builds on one base image and deploys to another. Automating container deployment with GitLab CI/CD covers building the image and deploying it as one reproducible pipeline step, so the image that passes CI is the exact image that runs in production — not a close approximation of it.

CI/CD pipeline diagram showing build, test, and deploy stages feeding into one consistent container image

And if your deployment already involves more than a docker run — multiple services, a database, ingress, secrets — templating that with Helm rather than a pile of one-off YAML files pays off the first time you need to redeploy with one change. Helm chart best practices is worth reading before your chart grows past the point where it's easy to restructure. If you're weighing whether to run that chart yourself or on a managed K3s platform, Kubo runs standard Kubernetes with the ingress, TLS, and monitoring plumbing already wired in, so a fix like this one ships the same way whether you're testing it locally or rolling it out to every pod.