Prisma · tool · fg-0291

prisma generate fails in CI or Docker builds with 'PrismaConfigEnvError: Cannot resolve environment variable: DATABASE_URL'

Error: PrismaConfigEnvError: Cannot resolve environment variable: DATABASE_URL.

Verified 2026-10-15 · Confirmed by 0 builders · Trust 50/100

Cause

Prisma 7 loads prisma.config.ts for every CLI command, and env() from prisma/config throws when the variable is unset, even for generate. Prisma 7 also stopped reading the env file automatically, so the config has to load dotenv itself.

Fix

Import dotenv/config at the top of the config and read process.env directly, so generate runs without a URL while migrate commands still fail with a clear message.

Apply

import 'dotenv/config'
import { defineConfig } from 'prisma/config'
export default defineConfig({
  schema: 'prisma/schema.prisma',
  migrations: { path: 'prisma/migrations' },
  datasource: { url: process.env.DATABASE_URL },
})

Affects: Prisma ORM 7.0 and later; the process.env form is accepted by 7.8.0 and later and was verified on 7.10.0

Sources

Have your agent know this before it fails

claude mcp add --transport http footgun https://getfootgun.com/api/mcp