prisma: Bun: Can't `prisma generate` on Docker

Bug description

Trying to running prisma generate inside Docker container build, but it does not happen. See console output:

It started some Prisma engine downloading, but gives up in about 1~2 seconds after started. Nothing happens, and i can’t prisma generate on container.

Running at my Windows macinhe (through WSL/ Ubuntu) it works fine. Example repository: https://github.com/medeiroshudson/MiniCommerce

(Prisma folder is located at /packages/infrastructure/data/)

# ls
apps  bun.lockb  config  node_modules  package.json  packages  tsconfig.json  turbo.json
# bunx prisma generate
> Downloading Prisma engines for Node-API for debian-openssl-1.1.x [=======             ] 35%#

It always “fails” at some random percentage.

How to reproduce

1 - Run docker container (see github repo) 2 - Exec bunx prisma generate inside container 3 - See nothing happening

Expected behavior

Generating prisma client

Prisma information

// Add your schema.prisma
// Add your code using Prisma Client

Environment & setup

Windows WSL Docker Bun 1.0.3

Prisma Version

^5.3.1

About this issue

  • Original URL
  • State: open
  • Created 9 months ago
  • Reactions: 22
  • Comments: 25 (1 by maintainers)

Most upvoted comments

I faced a similar issue when using Prisma with Bun. The Prisma generate runs ok when I use bun but it’s unable to create a Prisma client when running with docker. Tried to search around but didn’t find any solution yet.

My workaround is to generate it locally with bun (in a non-docker environment) and then ship it with a docker image. Note that I work to change the output of the generator to a different location rather than the default inside node_module. It helps simplify the Dockerfile setup.

Here’s my setup prisma.schema

  provider      = "prisma-client-js"
  output        = "../generated/prisma-client" //Change output to custom path
  binaryTargets = ["native", "debian-openssl-1.1.x"]
}

Setup in Dockerfile

WORKDIR /usr/src/app

COPY package*.json bun.lockb ./
RUN bun install
COPY . .

# If your `generated/prisma-client` is not in the Docker build context (the directory containing your Dockerfile), 
# you'll need to place it within the build context or adjust your project structure accordingly. E.g

ENV NODE_ENV production

CMD [ "bun", "start" ]

This solution works for me but it violates the docker concept to keep the environment consistent and bring an additional step in the build process to generate clients. In my case, it’s good enough to go with the current situation until I find a better alternative or receive an update from Prisma.

Note that the Prisma client runs differently on different OS so the deployment needs to be tested carefully

Please consider fixing this!

Can someone explain what goes wrong in the plain bun image without Node? The process just seems to die, which sounds very much like a bun problem and not something that Prisma is causing. Is there a way to get more output from bunx? Or some other way to invoke the Prisma CLI so that we see what causes prisma generate to just return?

@janpio There appears to have been some progress at Bun to resolve this but some issues still remain. I added more information in https://github.com/oven-sh/bun/issues/5320 including an easy-to-reproduce example.

Update: Got it working after install nodejs on docker container. Is there some way to not depending nodejs binaries?

Maybe a feature request? Thanks.

Prisma and BunJS don’t particularly go well on Docker so here is a Dockerfile that’ll solve your problems once and for all.

# > 1. OS SET UP --
FROM ubuntu:22.04

# > 1.a -- Install various essential dependencies
RUN apt-get update && apt-get install -y curl gnupg zip unzip

# > 1.b Install NodeJS
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
    apt-get install -y nodejs

# > 1.c Install BunJS
ENV BUN_INSTALL=$HOME/bun
RUN curl -fsSL https://bun.sh/install | bash
ENV PATH=$PATH:$HOME/bun/bin

# > 2. PROJECT SET UP --
# > 2.a -- Set up working directory for the project 
WORKDIR /app

# > 2.b -- Copy essential dependency specification files
COPY package.json .
COPY bun.lockb .
COPY tsconfig.json .
COPY prisma prisma

# > 2.c -- Install dependencies
RUN bun install

# > 2.d -- Run prisma codegen
RUN bunx prisma generate

# > 2.e -- Copy essential files and folders
COPY src src

# > 2.f -- Set up various environment variables
ENV PORT 8080

# > 3. RUN PROJECT --
# > 3.a -- Expose various ports as necessary
EXPOSE 8080

# > 3.b -- Run
CMD ["bun", "start"]

Dockerfile as GitHub Gist

Appears to be fixed in Bun 1.0.30

@vutran-tvg Worked for me too, thanks! yes, indeed a not very automated build process…

Thanks man, I had the exact same issue, while using Bun in combination with Prisma. Installing node into the docker container worked for me as well.