#Next.js and prisma in a container not working
4 messages · Page 1 of 1 (latest)
Your issue is a common one when using Prisma with Next.js in Docker, especially with a custom client output path. Prisma expects the query engine binary to be present in specific locations at runtime, and Next.js' build/bundling can complicate this.
Key points and solutions:
-
Custom Output Path Issue:
When you set a custom output (like../src/generated/prisma), Prisma may not look for the query engine in that directory at runtime. In Next.js, especially with serverless or standalone output, the runtime may not have access to the generated client or its binaries in the expected place. This is a known issue and has been reported multiple times. The engine is often searched for in the root,.prisma/client, or@prisma/clientdirectories, not your custom output path. See this issue and this discussion. -
Copying the Engine Binary:
You need to ensure that the generated Prisma client and its engine binaries are copied to a location where Prisma expects them at runtime. If you use a custom output, you may need to manually copy the generated client and the engine binary tonode_modules/@prisma/clientin your Dockerfile after runningprisma generate:# After prisma generate COPY --from=builder /app/src/generated/prisma /app/node_modules/@prisma/clientThis ensures the engine is available where Prisma looks for it in production containers see this maintainer comment.
-
General Advice:
- Avoid custom output unless necessary. If you must use it, always copy the generated client to
node_modules/@prisma/clientin your final image. - Make sure
binaryTargetsincludes the correct platform for your Docker image (which you have done).
- Avoid custom output unless necessary. If you must use it, always copy the generated client to
Summary:
Your error is likely because Prisma can't find the engine in the expected place due to the cust
om output. Copy the generated client to node_modules/@prisma/client in your Dockerfile after building, or remove the custom output if possible. This should resolve the query engine not found error.
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.