P
Prisma2w ago
Luex

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:
prisma db:generate $ prisma generate
│ Environment variables loaded from .env
│ Prisma schema loaded from schema.prisma
│ Error: Command failed with exit code 1: npm i @prisma/client@6.5.0 --silent
└─ Exited with code 1
error: script "db:generate" exited with code 1
prisma db:generate $ prisma generate
│ Environment variables loaded from .env
│ Prisma schema loaded from schema.prisma
│ Error: Command failed with exit code 1: npm i @prisma/client@6.5.0 --silent
└─ Exited with code 1
error: script "db:generate" exited with code 1
How can i run prisma inside a monorepo with multiple packages?
2 Replies
Prisma AI Help
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:
bun add @prisma/client
bun add -D prisma
bun add @prisma/client
bun add -D prisma
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:
generator client {
provider = "prisma-client-js"
output = "../src/__generated__/prisma"
}
generator client {
provider = "prisma-client-js"
output = "../src/__generated__/prisma"
}
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:
# Install Node.js first, then run Prisma commands
bun prisma generate
# Install Node.js first, then run Prisma commands
bun prisma generate
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:
bun prisma generate --schema=src/prisma/schema.prisma
bun prisma generate --schema=src/prisma/schema.prisma
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:
FROM node:23

WORKDIR /app

RUN npm install -g bun

COPY . .
RUN bun install
RUN bun prisma migrate deploy
RUN bun prisma generate

RUN bun run build

CMD ["bun", "run", "start:prod"]
FROM node:23

WORKDIR /app

RUN npm install -g bun

COPY . .
RUN bun install
RUN bun prisma migrate deploy
RUN bun prisma generate

RUN bun run build

CMD ["bun", "run", "start:prod"]
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.
Luex
LuexOP2w ago
The error log of the failed npm call contains this:
npm error code EUNSUPPORTEDPROTOCOL
npm error Unsupported URL Type "workspace:": workspace:*
npm error code EUNSUPPORTEDPROTOCOL
npm error Unsupported URL Type "workspace:": workspace:*
I was able to solve my issue. I renamed my package from "prisma" to some other name. The name should be different from prisma.

Did you find this page helpful?