Closed sum117 closed 7 months ago
Issue with Prisma CLI commands seems to be fixed in v1.0.2. Run bun upgrade
and try again. Reopen this issue if it doesn't work for you with additional OS details.
I use devcontainer
with the docker image mcr.microsoft.com/devcontainers/base:jammy
.
I have the same problem with bun version 1.0.2
.
When i only run:
bunx prisma
It runs gives me the --help
response. But nothing else works:
bunx prisma init
bunx prisma migrate
bunx prisma generate
Sometimes randomly, it says this:
Downloading Prisma engines for Node-API for debian-openssl-3.0.x [================ ] 81%
1.0.2 with Docker also has non-working prisma generate
.
OS Info:
oven/bun:1.0.2
Docker version 24.0.5, build ced0996600
Arch Linux 6.5.3-zen1-1-zen
Same issue here, in the oven/bun
docker container:
root@69248dd04828:/app# bun -v
1.0.2
root@69248dd04828:/app# bunx prisma migrate deploy
> Downloading Prisma engines for Node-API for debian-openssl-1.1.x [========= ] 47%root@69248dd04828:/app#
Stops are 47%, no errors or anything.
I'm also running docker on wsl, but I don't think that matters?
Thanks for all the feedback guys. I have reopened this issue because of it. I'm sorry this is still a problem for your use case and I ask you pardon for my oversight.
The core team will hopefully come back to us, I'm sure of it!
Same issue here, bunx prisma generate
completes but client is not generated
+1
First you need to include nodejs
in your Docker image. That is required for Prisma to work with Bun:
# Dockerfile COPY --from=node:18 /usr/local/bin/node /usr/local/bin/node
After that you need to trust the Prisma client package, so it can execute postinstall
scripts:
# package.json "trustedDependencies": [ "@prisma/client" ],
With this, I'm able to run bun install
and it generates my schema without any problems.
I can also run bunx prisma generate
without any problems. Here is my full Dockerfile:
FROM oven/bun:1.0.2 WORKDIR /opt/app COPY --from=node:18 /usr/local/bin/node /usr/local/bin/node COPY ./packages ./packages COPY ./package.json ./ COPY ./bun.lockb ./ # Install packages RUN bun install # Run generation RUN bunx prisma generate
It still dosen't work with the ARM image. I think Prisma missing a ARM build of the Debian engine.
First you need to include
nodejs
in your Docker image. That is required for Prisma to work with Bun:
Kinda defeats the purpose of using Bun as it is a Node.js replacement 😕
It would also make the image larger, I don't want to ship Node.js and Bun to run migrations.
Kinda defeats the purpose of using Bun as it is a Node.js replacement 😕
I agree. This is not a super optimal solution, but for now, I think it's more clean than copying node_modules
around.
It would also make the image larger, I don't want to ship Node.js and Bun to run migrations.
You can use a multi-stage build, if you don't want to include Node.js in your final image, or delete it after prisma
commandas has ran. Something like this: RUN rm -rf /usr/local/bin/node
I'm experiencing this issue as well. I tried a different approach which is not optimal as well, but dont seem to work. I ran bun run prisma generate
locally and copy the generated files to a new folder prisma-client/client
. Then when I build my Docker Image i copy that folder into the /node_modules/@prisma/client folder.
This is what my Dockerfile
looks like:
FROM oven/bun:1.0.2
ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY package.json bun.lockb ./
RUN bun install
COPY prisma-client/client /node_modules/@prisma/client
COPY . .
RUN rm -rf prisma-client
EXPOSE 3000
CMD [ "bun", "run", "start" ]
Unfortunately I'm still seing the same error:
2023-09-22 11:58:58 $ bun run src/index.ts
2023-09-22 11:58:58
2023-09-22 11:58:58
2023-09-22 11:58:58 error: Cannot find module ".prisma/client/index" from "/usr/src/app/node_modules/@prisma/client/index.js"
2023-09-22 11:58:58 error: script "start" exited with code 1 (SIGHUP)
By following @sorenhansendk example I was able to get it working, but I had to define a custom output path for the prisma generated files:
You can use a multi-stage build, if you don't want to include Node.js in your final image, or delete it after
prisma
commandas has ran. Something like this:RUN rm -rf /usr/local/bin/node
True, but for my usecase I need to run migrations when the container starts, which is only possible with Prisma using npx (afaik). So it's unfortunately not a solution for me, I think? Or can you run bunx
without node after bun install
with node? I'll try it later. Thank you for providing a work-around at least!
So it's unfortunately not a solution for me, I think? Or can you run bunx without node after bun install with node?
I have not tested migrations without Node.js included. I think you will run into problems - but let us please know the result 👍
Just to add on to this. The current state of bun install
using Bun v1.0.3
with prisma for us is this.
Locally bun install
does not execute the postinstall script to generate the client in node_modules/.prisma/
. But if you run bun run prisma generate
it works as expected and generates the client.
In our Gitlab CI/CD runners using docker, bun install
also does not execute the postinstall script. But here even running bun run prisma generate
does nothing as well. We can confirm this by running tsc
afterwards and it fails every place we import the Prisma Client or the types it generates.
This still not working with bun 1.0.3 My docker file
FROM oven/bun:1.0.3 as base
WORKDIR /app/
COPY package.json bun.lockb ./
COPY ./src ./src
COPY ./prisma ./prisma
RUN bun install --production
RUN bunx prisma generate
CMD bun run deploy-one
Alright, I was able to run it by also having node
installed in the container.
I don't know but, this might be a prisma
problem, looking specifically for node
, not sure.
Here's my devcontainer.json
:
{
"name": "Bun & Node.js & TypeScript",
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye",
"features": {
"ghcr.io/shyim/devcontainers-features/bun:0": {}
},
"postCreateCommand": "bun i",
}
Ran into the same issue today. Adding with some speculations on my side:
It's super weird, bun prisma generate
prints nothing to the console on build/start (on railway.app), but works perfectly locally.
I guess bun (at some point) runs Node (instead of itself), but then fails silently if Node is not installed. Locally, this works, since I have both installed.
There is provably something in Prisma that has a hard dependency on Node somewhere e.g. with a shebang #!/usr/bin/node
, or a spawn/exec somewhere.
It's just so odd that it's entirely silent. I guess I'll include Node18 with the container for now, but will spend some time this week to investigate.
In Docker it fails silently and in local it throws this error:
✘ [ERROR] Could not resolve ".prisma/client/index-browser"
node_modules/@prisma/client/index-browser.js:1:23:
1 │ const prisma = require('.prisma/client/index-browser')
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can mark the path ".prisma/client/index-browser" as external to
exclude it from the bundle, which will remove this error. You can also
surround this "require" call with a try/catch block to handle this
failure at run-time instead of bundle-time.
I have created a repo where Prisma and Bun do not play well in Docker nor non-Docker: https://github.com/judocode/prisma-bun. I currently see the following problem in Docker:
> [6/6] RUN bun run prisma generate:
16.82 error: "prisma" exited with code 9 (SIGKILL)
------
Dockerfile:11
--------------------
9 | COPY . .
10 |
11 | >>> RUN bun run prisma generate
12 |
13 | CMD ["bun", "./src/index.ts"]
--------------------
ERROR: failed to solve: process "/bin/sh -c bun run prisma generate" did not complete successfully: exit code: 9
Hi people.
Does somebody have this problem when using docker with prisma and bun?:
error TS2305: Module '"@prisma/client"' has no exported member 'PrismaClient'.
If a run it locally, this problem doesn't show up! but running docker build
, it fails!
I made a stupid mistake calling cli generate without schema.prisma file this dockerfile works for me
FROM oven/bun:latest
WORKDIR /usr/src/app
# Install nodejs using n
RUN apt-get -y update; apt-get -y install curl
ARG NODE_VERSION=18
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \
&& bash n $NODE_VERSION \
&& rm n \
&& npm install -g n
COPY bun.lockb package.json ./
RUN bun install
# You must ensure that schema.prisma is already in the directory
COPY . .
RUN bunx prisma generate
RUN bun run build
ENV NODE_ENV production
EXPOSE 3000
ENTRYPOINT [ "bun", "run", "start:prod" ]
This is the dockerfile generated by fly.io. and guess what? it doesn't work :( exactly at the bun run build because it can't find prisma client types HELP!
# syntax = docker/dockerfile:1
# Adjust BUN_VERSION as desired
ARG BUN_VERSION=1.0.7
FROM oven/bun:${BUN_VERSION} as base
LABEL fly_launch_runtime="Next.js/Prisma"
# Next.js/Prisma app lives here
WORKDIR /app
# Set production environment
ENV NODE_ENV="production"
# Throw-away build stage to reduce size of final image
FROM base as build
# Install packages needed to build node modules
RUN apt-get update -qq && apt-get install -y build-essential openssl pkg-config python-is-python3
# Install node modules
COPY --link bun.lockb package.json ./
RUN bun install
# Generate Prisma Client
COPY --link prisma .
RUN bun prisma generate
# Copy application code
COPY --link . .
# Build application
RUN bun run build
# Remove development dependencies
RUN rm -rf node_modules && bun install --ci
# Final stage for app image
FROM base
# Install packages needed for deployment
RUN apt-get update -qq && apt-get install --no-install-recommends -y openssl && rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Copy built application
COPY --from=build /app /app
# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD [ "bun", "run", "start" ]
In fact, you also need to install node. Prisma generate needs to generate a node addons.
In fact, you also need to install node. Prisma generate needs to generate a node addons.
Yes tried it, it works. But there is another bug where bun leaks memory and VM shuts down due to that.
even though having also node in the container works on my pc, same container doesn't work on the server: https://github.com/oven-sh/bun/issues/3315#issuecomment-1768976067
had to switch to node. there's certainly a memory leak.
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's help 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 all the environment consistent and brings an additional step in the build process to generate the Prisma client. Anw, it's good enough to go with the current situation until I find a better alternative or receive updates from Prisma. Note that the Prisma client runs differently on different OS so the deployment needs to be tested carefully
yes bunx doesn't work with prisma, is it a prisma bug or a bun bug ?
Wasted a few days on this until finally found this thread.. guess I'll have to switch back to using node
Hi people. Does somebody have this problem when using docker with prisma and bun?:
error TS2305: Module '"@prisma/client"' has no exported member 'PrismaClient'.
If a run it locally, this problem doesn't show up! but running
docker build
, it fails!
This is exactly what I have! I'm running ReviOS 11 so I thought it's due to some of it's optimizations, I can never get PrismaClient
to be detected and neither can i run any bunx prisma
codes.... only --help
works
All is perfect now, turns out I also needed an installation of nodeJS itself (not just bunJS)., I'm guessing this would be required in a docker container too, Prisma definitely runs some node-specific code somewhere
Weird, mine is failing to parse prisma itself -
> [build 7/10] RUN bunx prisma generate:
#0 0.367 /app/node_modules/prisma/build/index.js:867
#0 0.367 if (typeof process !== "undefined" && typeof process.stderr?.write !== "function") {
#0 0.367 ^
#0 0.367
#0 0.367 SyntaxError: Unexpected token '.'
#0 0.367 at wrapSafe (internal/modules/cjs/loader.js:915:16)
#0 0.367 at Module._compile (internal/modules/cjs/loader.js:963:27)
#0 0.367 at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
#0 0.367 at Module.load (internal/modules/cjs/loader.js:863:32)
#0 0.367 at Function.Module._load (internal/modules/cjs/loader.js:708:14)
#0 0.367 at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
#0 0.367 at internal/main/run_main_module.js:17:47
------
Optional chaining has been around for a while and this is node v20 so I don't know why it's happening here
@gausie me too, in wsl
@gausie suggest using prisma by installing node --> npx prisma
,
then use @prisma/client in bun
Has anyone found a solution that does not involve installing Prisma with node?
Hei, here is my simpmle solution, same ideas with @Xu-pixel, Not ideal to use right away but probably you can get some ideas.
So since bunx prisma
is not working with oven/bun
then what I do is to use node
docker image instead. Then I install bun with npm
. My dockerfile will be just like this below.
FROM node:20-slim
WORKDIR /app
ENV NODE_ENV="production"
# Install needed libs for prisma, e.g. openssl, etc..
RUN apt-get update -qq && apt-get install -y build-essential openssl pkg-config python-is-python3
# Install bun
RUN npm install -g bun
# Install node modules
COPY bun.lockb package.json ./
# Clean install
RUN bun install --ci
# Generate Prisma Client
COPY . .
# FIXME: `bunx` has issue with prisma cli, so we use `npx` instead.
RUN npx prisma generate
# Start the server by default, this can be split to another build step to make the size much smaller
EXPOSE 3000
CMD [ "bun", "./src/index.ts" ]
There are some improvements of this that you can do
bun run
part to a smaller one. node:20-slim
and all libs stuffs. you can use anything as well, the point here is you need npx
for run prisma generate
.bunx primsa migrate deploy
because bunx prisma
won't work anyway.Followed @JinYuSha0's approach of installing Node and running bunx prisma generate
. It was pretty straightfoward from there. Here's the very rough Dockerfile I wrote:
FROM oven/bun:1 AS base
# Install nodejs using n
# Apparently bunx needs node to run `prisma generate` lol
RUN apt-get -y update; apt-get -y install curl
ARG NODE_VERSION=18
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \
&& bash n $NODE_VERSION \
&& rm n \
&& npm install -g n
# Hacky way of copying over stuff from NX
WORKDIR /usr/src/app
COPY tsconfig.base.json .
COPY .eslintrc.json .
COPY prisma prisma
COPY apps/our-app apps/our-app
COPY apps/our-app/custom-package.json package.json
RUN bun install
RUN bunx prisma generate
CMD ["bun", "apps/our-app/src/index.ts"]
Haven't explore multi-stage builds yet as I wanted to just make it work. The image produced here ballooned to 750MB probably because of Node lol. I'll iterate more on this and will message here if I discover anything significant.
Just reiterating, this issue still persists on 1.0.27. When running any prisma
command with Bun instead of Node.js, it fails silently (exit code 0).
Can be replicated with:
bunx --bun prisma --help
- fails
bunx prisma --help
- works (but you need Node.js installed and available - node -v
)
As others have said, current workaround is having Node installed. My workaround is:
FROM oven/bun:1-debian
COPY --from=node:18 /usr/local/bin/node /usr/local/bin/node
...
services:
app:
# image: oven/bun:1-debian
build:
context: ./docker/bun
...
I think i may have found a solution with pure Bun - no node installation. Send plenty US dollars to my paypal and i'll share 🤣 simmonsfrank gmail com 😊 Let me just recreate the issue to double-check
Has anyone found a solution that does not involve installing Prisma with node?
Check this article, scroll down to the very last paragraph. Note that the versions used are Bun 1.0.28, Prisma 5.10.2
https://medium.com/@simmonsfrank/beautiful-elysia-imprismad-in-a-jail-6518dd2af586
oh nice, ill have to try it again, must be the fix from the blog post on the release:
That solution does not work, i tried it. The person who made the blog post must have copied the generated folder into their docker context, so it was already there.
prisma generate does not work without node still.
Try bumping up your Bun and Prisma versions to the latest. 1.0.28 and 5.10.2 are out, respectively. I'm running ElysiaJS in a docker container as we speak. Not a single stitch of node here.
Yes that works, if you're building your docker container and the generated prisma client is already in the build context.
I attempted with the latest versions.
In your docker container you can run bun prisma migrate
and see there is still no output.
bunx prisma migrate
you mean ?
All is running perfectly for me bro.
Did you relink all mentions of @prisma/client
to generated
?
That solution does not work, i tried it. The person who made the blog post must have copied the generated folder into their docker context, so it was already there.
prisma generate does not work without node still.
Yeah, this fix was for a different error that occurred once prisma was actually running, the generator part is still broken unfortunately
I have tried using Prisma commands both in the latest canary
container and with a locally built version of Bun directly from the main
branch some hours ago and I still see Prisma silently failing:
root@4262fb6e72c4:~# bun x prisma init
> Downloading Prisma engines for Node-API for linux-arm64-openssl-3.0.x [====================] 99%root@4262fb6e72c4:~# bun x prisma init
> Downloading Prisma engines for Node-API for linux-arm64-openssl-3.0.x [========== ] 49%root@4262fb6e72c4:~# bun x prisma init
> Downloading Prisma engines for Node-API for linux-arm64-openssl-3.0.x [========== ] 49%root@4262fb6e72c4:~#
Sometimes Prisma commands succeed, but only lead to the discovery of other issues. For example, the output of prisma init
always ends with
error: Script not found "/tmp/bunx-0-prisma@latest/node_modules/prisma/build/child"
I cannot pinpoint this issue to an exact location in Prisma’s source code, but there is a line in the minified bundle that reads
childPath=path__default.default.join(eval("__dirname"),"child");
Changing child
to child.js
there removes the error message.
Also, prisma generate
fails for me when working with a larger schema. The error shows
Generator "/root/rating-tracker/node_modules/@prisma/client/generator-build/index.js" failed:
13849 |
13850 | // ../generator-helper/src/generatorHandler.ts
13851 | function generatorHandler(handler) {
13852 | byline(process.stdin).on("data", async (line) => {
13853 | console.log(String(line)); // I added this line
13854 | const json = JSON.parse(String(line));
^
SyntaxError: JSON Parse error: Unterminated string
at /root/rating-tracker/node_modules/@prisma/client/generator-build/index.js:13854:18
at /root/rating-tracker/node_modules/@prisma/client/generator-build/index.js:13852:43
at addChunk (node:stream:1941:43)
at readableAddChunk (node:stream:1895:59)
at /root/rating-tracker/node_modules/@prisma/client/generator-build/index.js:13826:12
at /root/rating-tracker/node_modules/@prisma/client/generator-build/index.js:13838:3
at final (node:stream:3247:37)
at callFinal (node:stream:2778:45)
The output from my console.log
indeed shows a huge JSON output beginning with {"jsonrpc":"2.0","method":"generate","params":…
and ending in the middle of nowhere:
…se,"isNullable":true,"inputTypes":[{"type":"Float","location":"scalar","isList":false},{"type":"Null","location":"scalar","isList":false}]},{"name":"description","isRequired":false,"isNullable":true,"inputTypes":[{"type":"String","location":"scalar","isList":false},{"type":"Null","location":"scalar","isList":false}]},{"name":"marketCap","isRequired":false,"isNullable":true,"inputTypes":[{"type":"Float","location":"scalar","isList":false},{"type":"Null","location":"scalar","isList":false}]}]},{"name":"StockUpdateManyMutationInput","constraints":{"maxNumFields
This is as far as I get. Not sure what to make of all this, I just thought to leave some more information here that might help track down remaining issues. Let me know if you need anything else.
PS: The example above is easily reproducable by using Prisma’s quickstart walkthrough and a non-trivial Schema:
mkdir hello-prisma
cd hello-prisma
bun init -y
bun install typescript ts-node @types/node
bun install prisma
bun x prisma init --datasource-provider sqlite
# now copy some schema to the prisma folder, I used mine from https://github.com/marvinruder/rating-tracker/blob/main/packages/backend/prisma/schema.prisma
bun x prisma generate
# you can add `console.log(String(line));` to node_modules/@prisma/client/generator-build/index.js:13853 to see the json-rpc messages of which parsing fails
Still seeing this issue in today’s canary
:
docker run --rm -it --entrypoint /bin/sh oven/bun:canary-alpine # also tried with Debian-based oven/bun:canary, same result
/home/bun/app # bunx prisma init
> Downloading Prisma engines for Node-API for linux-musl-arm64-openssl-3.0.x [================= ] 87%/home/bun/app #
/home/bun/app # bun --revision
1.0.29+2fb6733ee
/home/bun/app #
Confirming this issue is still not fixed. The previous PRs made good progress, but prisma generate
continues to not work when used in Bun.
"Downloading" hangs or exits prematurely, before it finishes:
❯ bun --bun prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
> Downloading Prisma engines for Node-API for darwin-arm64 [============== ] 69%
This issue will only reproduce when prisma engines have not yet been downloaded on the machine, like when using Docker and the Prisma engine is not cached on-disk.
There is also an issue when prisma calls child_process.fork but I'm not able to isolate it yet.
The issue now seems to be with node-fetch
. Here's a minified repro:
import hasha from "hasha"; // bun add hasha@5.2.2
import zlib from "zlib";
// import fetch from "node-fetch";
import fetch from "./node_modules/node-fetch/lib/index.mjs"; // bun add node-fetch@2.7.0
async function downloadZip(url2) {
const response = await fetch(url2, { compress: false });
if (!response.ok) throw new Error('fail');
return await new Promise(async (resolve3, reject2) => {
let bytesRead = 0;
response.body
.on("error", reject2)
.on("data", (chunk) => { bytesRead += chunk.length });
const gunzip = zlib.createGunzip();
gunzip.on("error", reject2);
const zipStream = response.body.pipe(gunzip);
const zippedHashPromise = hasha.fromStream(response.body, { algorithm: "sha256" });
const hashPromise = hasha.fromStream(zipStream, { algorithm: "sha256" });
console.log("will await");
await hashPromise;
await zippedHashPromise;
console.log("all okay");
resolve3();
});
}
const url = "https://binaries.prisma.sh/all_commits/5a9203d0590c951969e85a7d07215503f4672eb9/debian-openssl-1.1.x/libquery_engine.so.node.gz";
const array = new Array(10).fill(url);
const promises = array.map((url) => downloadZip(url));
await Promise.all(promises);
console.log("DONE");
This will never log DONE
, it will hang after 4 or so all okay
logs.
Note that I use the explicit node-fetch
import because Prisma bundles the OG node-fetch
with it, which means it isn't replaced with Bun's version (if you swap it out for the commented-out import, it will work and reach DONE
).
Haven't dug any deeper than this atm, but this narrows it down quite a bit
switched to drizzle after all.
What version of Bun is running?
1.0.1+31aec4ebe325982fc0ef27498984b0ad9969162b
What platform is your computer?
Microsoft Windows NT 10.0.22621.0 x64
What steps can reproduce the bug?
Docker:
WSL:
Install WSL normally...
Make bun installation inside Ubuntu.
Try to follow this exact guide: https://bun.sh/guides/ecosystem/prisma
What is the expected behavior?
Prisma installs normally
What do you see instead?
This, download never finishes:
Additional information
No response