Using prisma in a bun monorepo
I am using a bun based monorepo with bun workspaces. I have package called
prisma
for my prisma client and schema. If i try to run prisma generate
, it fails with this error:
How can i run prisma inside a monorepo with multiple packages?2 Replies
You opted for speed from this bot. Let's conjure up an answer right now!
I can see you're having issues running
prisma generate
in a Bun monorepo workspace setup. This is a common issue when using Prisma in monorepos, as Prisma tries to install dependencies using npm by default, which can cause conflicts in different package manager environments.
Based on the error message, Prisma is trying to use npm to install @prisma/client
, but this is failing in your Bun workspace environment.
Here are some solutions you can try:
1. Pre-install the required dependencies
The simplest solution is to manually install both prisma
and @prisma/client
in your package before running the generate command:
This is often enough to prevent Prisma from trying to auto-install dependencies during generation.
2. Use a custom output path
You can modify your schema.prisma file to use a custom output path outside of node_modules:
3. Install Node.js alongside Bun
Several users have reported that Prisma's generate command requires Node.js to function properly, even when using Bun:
As mentioned in this GitHub issue, some users found that installing Node.js alongside Bun resolved their issues.
4. Use explicit schema path
If Prisma is having trouble finding your schema, specify the path explicitly:
For Docker environments
If you're using Docker, you might need to use Node as a base image and install Bun on top of it:
This approach was suggested in [this GitHub issue](https://github.
com/prisma/prisma/issues/21277) as a workaround for Bun environments.
The core issue is that Prisma's CLI tools often have assumptions about the package manager being used, and monorepo setups with alternative package managers like Bun can cause conflicts. Pre-installing the dependencies and using custom output paths are the most reliable workarounds for these scenarios.
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.The error log of the failed npm call contains this:
I was able to solve my issue. I renamed my package from "prisma" to some other name. The name should be different from prisma.