DEV Community

Andreas Bergström
Andreas Bergström

Posted on • Originally published at andreasbergstrom.dev

Keeping the Prisma CLI out of a Bun runtime image

This site's runtime Docker image was 423 MB. After one Bun install flag and a one-line Dockerfile change, it's 267 MB — no functional change, just less Prisma CLI tooling sitting on disk that the server never imports.

The interesting part is why the obvious fix (moving prisma to devDependencies) doesn't do anything on its own. @prisma/client declares prisma as an optional peer dependency, and Bun installs optional peers by default. From there, transitive deps drag in @prisma/engines, @prisma/studio-core, @electric-sql/pglite, and ~160 MB of code the server never imports.

The fix is bun install --omit=peer, plus narrowing the runtime stage's COPY --from=builder /app/node_modules/@prisma line to just @prisma/client. The full post covers the trap, the fix, and where migrations have to run once the CLI is gone from the runtime image.


Originally published at andreasbergstrom.dev — read the full post there.

Top comments (0)