oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.09k stars 2.47k forks source link

Prisma does not work with bun alpine docker image. #10892

Closed hiroaki2020 closed 1 week ago

hiroaki2020 commented 1 week ago

What version of Bun is running?

v1.1.7

What platform is your computer?

MacOS M2 chip

What steps can reproduce the bug?

When I try to run prisma on oven/bun docker image(bun runtime official image), I got the following error.

PrismaClientInitializationError: Unable to require(`/home/bun/app/node_modules/.prisma/client/libquery_engine-linux-musl-arm64-openssl-3.0.x.so.node`).
2024-05-07 18:57:17 The Prisma engines do not seem to be compatible with your system. Please refer to the documentation about Prisma's system requirements: https://pris.ly/d/system-requirements
2024-05-07 18:57:17 
2024-05-07 18:57:17 Details: /usr/lib/libc.so: invalid ELF header
2024-05-07 18:57:17       at new e (/home/bun/app/node_modules/@prisma/client/runtime/library.js:22:1872)
2024-05-07 18:57:17       at /home/bun/app/node_modules/@prisma/client/runtime/library.js:111:10219
2024-05-07 18:57:17 
2024-05-07 18:57:17 Bun v1.1.7 (Linux arm64)

run docker image oven/bun:1.1.7-alpine and enter it setup Nest.js + GraphQL + apollo run prisma migrate + generate. Those are successful. When I start container, I got the error above. Actualy when I ran prisma -v to get version I got the same error.

What is the expected behavior?

work properly without the error

What do you see instead?

No response

Additional information

Environment & setup host PC OS: macOS host PC chip: apple sillicon(M2) docker OS: alpine. It's on docker for Mac. Database: PostgreSQL Node.js version: I use bun instead. Prisma Version prisma + prisma client version is 5.13.0

monkfromearth commented 1 week ago

If it is of any help, this is the kind of template we use at our workplace to make Bun-based Docker Images.

We use a Node image that has Bun installed to generate the Prisma Types. Then, we copy over the node_modules to a Bun Image where we serve it through our script.

We do not compile the source code to a single entry point executable using Bun, instead use the code to run directly, only without --watch here.

This has served us well since the last 3-5 months, since we use started using Bun v1.0.1 in Production. We are now at Bun v1.1.6.

FROM <node image with bun installed>
WORKDIR /app
COPY package.json bun.lockb tsconfig.json ./
RUN bun install
COPY . .
RUN bun prisma migrate deploy
RUN bun prisma generate
RUN rm -rf node_modules && bun install --production && bun pm cache rm

FROM <bun official image>
WORKDIR /app
COPY --from=builder /app/node_modules node_modules
COPY . ./
EXPOSE <PORT>
ENTRYPOINT [ "bun" ] 
CMD ["serve"]
hiroaki2020 commented 1 week ago

@monkfromearth Thanks for sharing this. I'll keep trying a little bit more on this issue. I tried debian oven/bun image and clarified prisma is working. I only checked findMany() method, though.

Electroid commented 1 week ago

The root issue is that Bun does not support MUSL, and our alpine image is using a hacky way around it.

Electroid commented 1 week ago

Duplicate of #918