diff --git a/content/200-orm/400-tools/05-prisma-cli.mdx b/content/200-orm/400-tools/05-prisma-cli.mdx index b7cb38eb18..b95babe2a7 100644 --- a/content/200-orm/400-tools/05-prisma-cli.mdx +++ b/content/200-orm/400-tools/05-prisma-cli.mdx @@ -73,9 +73,15 @@ pnpm dlx prisma ### Bun ``` -bunx prisma +bunx --bun prisma ``` +:::note + +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. + +::: + ## Synopsis The `prisma` command can be called from command line once installed. When called without arguments, it will display its command usage and help document: diff --git a/content/200-orm/500-reference/325-prisma-config-reference.mdx b/content/200-orm/500-reference/325-prisma-config-reference.mdx index 89f86821c5..2b8b9e0c0c 100644 --- a/content/200-orm/500-reference/325-prisma-config-reference.mdx +++ b/content/200-orm/500-reference/325-prisma-config-reference.mdx @@ -607,7 +607,13 @@ tsx --env-file=.env ./prisma/seed.ts #### Using Bun -For Bun, `.env` files are automatically loaded without additional configuration. +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. + +:::note + +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. + +::: #### Type-safe environment variables @@ -738,14 +744,20 @@ pnpm prisma validate # → Still finds prisma.config.ts and resolves schema correctly ``` -### Behavior with `npm exec prisma` or `bun prisma` +### Behavior with `npx prisma` or `bunx --bun prisma` -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). +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). + +:::note + +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. + +::: Example run from the project root: ```bash -npm exec prisma validate +npx prisma validate # → Works as expected ``` @@ -753,14 +765,14 @@ Run from a subdirectory (fails): ```bash cd src -npm exec prisma validate +npx prisma validate # → Error: Could not find Prisma Schema... ``` To fix this, you can use the `--config` flag: ```bash -npm exec prisma -- --config ../prisma.config.ts validate +npx prisma validate --config ../prisma.config.ts ``` ### Global Prisma installations diff --git a/content/800-guides/370-bun.mdx b/content/800-guides/370-bun.mdx index 9152d87126..522f5e7af3 100644 --- a/content/800-guides/370-bun.mdx +++ b/content/800-guides/370-bun.mdx @@ -57,9 +57,15 @@ If you are using a different database provider (MySQL, SQL Server, SQLite), inst Initialize Prisma ORM with Prisma Postgres in your project: ```terminal -bun prisma init --db +bunx --bun prisma init --db ``` +:::note + +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. + +::: + :::info 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() Add the following content to the file: ```typescript file=prisma.config.ts -import 'dotenv/config' import { defineConfig, env } from 'prisma/config'; export default defineConfig({ @@ -219,6 +224,12 @@ export default defineConfig({ }); ``` +:::note + +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. + +::: + Run the seed script to populate your database: ```terminal diff --git a/content/800-guides/440-elysia.mdx b/content/800-guides/440-elysia.mdx index 31d4aa7e3d..e49c1c425a 100644 --- a/content/800-guides/440-elysia.mdx +++ b/content/800-guides/440-elysia.mdx @@ -52,7 +52,7 @@ If you are using a different database provider (MySQL, SQL Server, SQLite), inst Once installed, initialize Prisma in your project: ```terminal -bunx prisma init --db --output ../src/generated/prisma +bunx --bun prisma init --db --output ../src/generated/prisma ``` :::info @@ -111,8 +111,8 @@ This matches the Prisma Elysia example: it generates Prisma Client to `src/gener Run the following commands to create the database tables and generate the Prisma Client: ```terminal -bunx prisma migrate dev --name init -bunx prisma generate +bunx --bun prisma migrate dev --name init +bunx --bun prisma generate ``` ### 2.4. Seed the database @@ -163,13 +163,13 @@ main() Run the seed script: ```terminal -bunx prisma db seed +bunx --bun prisma db seed ``` And open Prisma Studio to inspect your data: ```terminal -bunx prisma studio +bunx --bun prisma studio ``` ## 3. Integrate Prisma into Elysia