Skip to content

Cannot run any Prisma commands or generate the client if the DATABASE_URL environment variable is not set #28869

Closed as duplicate

Description

@arielweinberger

Bug description

This started happening on Prisma 7, I don't understand if this is a bug or just an odd decision.

I should be able to run builds (which also use prisma generate) in my CI/Dockerfiles without having to provide the DATABASE_URL.

If my prisma.config.ts has a datasource defined that uses an env variable, then any prisma command just throws this:

Failed to load config file "./" as a TypeScript/JavaScript module. Error: PrismaConfigEnvError: Missing required environment variable: DATABASE_URL

Severity

⚠️ Major: Breaks core functionality (e.g., migrations fail)

Reproduction

import "dotenv/config";
import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  migrations: {
    path: "prisma/migrations",
  },
  datasource: {
    url: env("DATABASE_URL"),
  },
});

Then make sure DATABASE_URL isn't set, and run prisma generate.

Expected vs. Actual Behavior

As far as I'm aware, you only need this when running prisma db push or prisma migrate commands. This should NOT happen when generating the client.

Frequency

Consistently reproducible

Does this occur in development or production?

Only in development (e.g., CLI tools, migrations, Prisma Studio)

Is this a regression?

This does not work the same way it did in 6.15.

Workaround

Only workaround right now is to either downgrade to 6.15, or do something silly like DATABASE_URL=none prisma generate.

Prisma Schema & Queries

// Add relevant schema.prisma snippet
// Add relevant Prisma Client query

Irrelevant

Prisma Config

// Add your `prisma.config.ts`

Logs & Debug Info

// Debug logs here

Environment & Setup

  • OS:
  • Database:
  • Node.js version:
    Irrelevant

Prisma Version

// Prisma version output

7.x

Activity

  1. changed the title [-]Cannot run any Prisma command if the database env variable is not set (should only require during migration/runtime)[/-] [+]Cannot run any Prisma commands or generate the client if the `DATABASE_URL` environment variable is not set[/+] on Dec 5, 2025
  2. rhinodavid commented on Dec 5, 2025

    @rhinodavid

    +1 on this. We're running a turborepo monorepo with 4 prisma databases and in CI we just want to build clients. We don't even have the concept of a live database to connect to at that time. I suppose we could put in a dummy value but that seems like it should be unnecessary like OP said.

  3. rhinodavid commented on Dec 5, 2025

    @rhinodavid

    Seems like a dupe of #28590

  4. jkomyno commented on Dec 8, 2025

    @jkomyno
    Contributor

    Hi, I confirm this is a duplicate of #28590.
    I answered here, and alerted the colleagues in charge of the docs internally.

    The TL/DR is: if your environment variable isn't guaranteed to exist, you should not use the env() utility from prisma/config. Use process.env['DATASOURCE_URL'] instead.

  5. arielweinberger commented on Dec 8, 2025

    @arielweinberger
    Author

    Why is the env variable needed at all during client generation? This seems like a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions