Skip to content

Commit 85e7a8d

Browse files
docs: clarify Bun Prisma usage and Bun-specific config behavior (#7407)
1 parent fc2b719 commit 85e7a8d

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

content/200-orm/400-tools/05-prisma-cli.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,15 @@ pnpm dlx prisma
7373
### Bun
7474

7575
```
76-
bunx prisma
76+
bunx --bun prisma
7777
```
7878

79+
:::note
80+
81+
The `--bun` flag ensures Prisma runs with the Bun runtime. Without it, Prisma falls back to Node.js due to the `#!/usr/bin/env node` shebang in the CLI.
82+
83+
:::
84+
7985
## Synopsis
8086

8187
The `prisma` command can be called from command line once installed. When called without arguments, it will display its command usage and help document:

content/200-orm/500-reference/325-prisma-config-reference.mdx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,13 @@ tsx --env-file=.env ./prisma/seed.ts
607607

608608
#### Using Bun
609609

610-
For Bun, `.env` files are automatically loaded without additional configuration.
610+
For Bun, `.env` files are automatically loaded without additional configuration. The `import 'dotenv/config'` line that `prisma init` generates is not needed when using Bun and can be safely removed from your `prisma.config.ts` file.
611+
612+
:::note
613+
614+
When running Prisma CLI commands with Bun, use the `--bun` flag (e.g., `bunx --bun prisma init`) to ensure Prisma uses the Bun runtime instead of falling back to Node.js.
615+
616+
:::
611617

612618
#### Type-safe environment variables
613619

@@ -738,29 +744,35 @@ pnpm prisma validate
738744
# → Still finds prisma.config.ts and resolves schema correctly
739745
```
740746

741-
### Behavior with `npm exec prisma` or `bun prisma`
747+
### Behavior with `npx prisma` or `bunx --bun prisma`
742748

743-
When running via `npm exec prisma` or `bun prisma`, the CLI only detects the config file if the command is run from the **project root** (where `package.json` declares Prisma).
749+
When running via `npx prisma` or `bunx --bun prisma`, the CLI only detects the config file if the command is run from the **project root** (where `package.json` declares Prisma).
750+
751+
:::note
752+
753+
The `--bun` flag is required when using Bun to ensure Prisma runs with the Bun runtime. Without it, Prisma falls back to Node.js due to the `#!/usr/bin/env node` shebang in the CLI.
754+
755+
:::
744756

745757
Example run from the project root:
746758

747759
```bash
748-
npm exec prisma validate
760+
npx prisma validate
749761
# → Works as expected
750762
```
751763

752764
Run from a subdirectory (fails):
753765

754766
```bash
755767
cd src
756-
npm exec prisma validate
768+
npx prisma validate
757769
# → Error: Could not find Prisma Schema...
758770
```
759771

760772
To fix this, you can use the `--config` flag:
761773

762774
```bash
763-
npm exec prisma -- --config ../prisma.config.ts validate
775+
npx prisma validate --config ../prisma.config.ts
764776
```
765777

766778
### Global Prisma installations

content/800-guides/370-bun.mdx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,15 @@ If you are using a different database provider (MySQL, SQL Server, SQLite), inst
5757
Initialize Prisma ORM with Prisma Postgres in your project:
5858

5959
```terminal
60-
bun prisma init --db
60+
bunx --bun prisma init --db
6161
```
6262

63+
:::note
64+
65+
The `--bun` flag is required to ensure Prisma runs with the Bun runtime. Without it, Prisma falls back to Node.js due to the `#!/usr/bin/env node` shebang in the CLI.
66+
67+
:::
68+
6369
:::info
6470

6571
You'll need to answer a few questions while setting up your Prisma Postgres database. Select the region closest to your location and a memorable name for your database like "My Bun Project"
@@ -202,7 +208,6 @@ main()
202208
Add the following content to the file:
203209

204210
```typescript file=prisma.config.ts
205-
import 'dotenv/config'
206211
import { defineConfig, env } from 'prisma/config';
207212

208213
export default defineConfig({
@@ -219,6 +224,12 @@ export default defineConfig({
219224
});
220225
```
221226

227+
:::note
228+
229+
Unlike Node.js, Bun automatically loads `.env` files, so the `import 'dotenv/config'` line is not needed. If you see this import in your generated `prisma.config.ts`, you can safely remove it.
230+
231+
:::
232+
222233
Run the seed script to populate your database:
223234

224235
```terminal

content/800-guides/440-elysia.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ If you are using a different database provider (MySQL, SQL Server, SQLite), inst
5252
Once installed, initialize Prisma in your project:
5353

5454
```terminal
55-
bunx prisma init --db --output ../src/generated/prisma
55+
bunx --bun prisma init --db --output ../src/generated/prisma
5656
```
5757

5858
:::info
@@ -111,8 +111,8 @@ This matches the Prisma Elysia example: it generates Prisma Client to `src/gener
111111
Run the following commands to create the database tables and generate the Prisma Client:
112112

113113
```terminal
114-
bunx prisma migrate dev --name init
115-
bunx prisma generate
114+
bunx --bun prisma migrate dev --name init
115+
bunx --bun prisma generate
116116
```
117117

118118
### 2.4. Seed the database
@@ -163,13 +163,13 @@ main()
163163
Run the seed script:
164164

165165
```terminal
166-
bunx prisma db seed
166+
bunx --bun prisma db seed
167167
```
168168

169169
And open Prisma Studio to inspect your data:
170170

171171
```terminal
172-
bunx prisma studio
172+
bunx --bun prisma studio
173173
```
174174

175175
## 3. Integrate Prisma into Elysia

0 commit comments

Comments
 (0)