#Next.js and prisma in a container not working

4 messages · Page 1 of 1 (latest)

fringe doveBOT
#

You chose to compile with the bot. One moment while I piece together your answer…

fringe doveBOT
# fringe dove You chose to compile with the bot. One moment while I piece together your answer...

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:

  1. 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/client directories, not your custom output path. See this issue and this discussion.

  2. 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 to node_modules/@prisma/client in your Dockerfile after running prisma generate:

    # After prisma generate
    COPY --from=builder /app/src/generated/prisma /app/node_modules/@prisma/client
    

    This ensures the engine is available where Prisma looks for it in production containers see this maintainer comment.

  3. General Advice:

    • Avoid custom output unless necessary. If you must use it, always copy the generated client to node_modules/@prisma/client in your final image.
    • Make sure binaryTargets includes the correct platform for your Docker image (which you have done).

Summary:
Your error is likely because Prisma can't find the engine in the expected place due to the cust

fringe doveBOT
fringe doveBOT