Skip to content
Latchkey

Prisma "PrismaClientInitializationError" at startup in CI

PrismaClientInitializationError is raised when constructing or first using PrismaClient fails: a missing engine binary, an unset connection string, or an unreachable database. The message names which of these it is.

What this error means

The process crashes at boot with "PrismaClientInitializationError" and a nested reason such as a missing engine, an invalid connection string, or an unreachable server.

Prisma
PrismaClientInitializationError: Invalid `prisma.user.findMany()` invocation:
error: Error validating datasource `db`: the URL must start with the protocol `postgresql://` or `postgres://`.

Common causes

The connection string is missing or malformed

An unset or wrong DATABASE_URL gives the datasource an invalid URL, and the client refuses to initialize.

The engine or database is not ready

A missing engine binary or a database service that is not yet up surfaces as an initialization error at first use.

How to fix it

Read the nested reason and fix it

  1. Read the message under PrismaClientInitializationError.
  2. For a URL error, set a valid DATABASE_URL in the step env.
  3. For an engine error, verify binaryTargets and that generate ran.
.github/workflows/ci.yml
env:
  DATABASE_URL: postgresql://postgres:postgres@localhost:5432/app

Wait for the database before connecting

Ensure the database service is accepting connections before the app or tests construct the client.

Terminal
until pg_isready -h localhost -p 5432; do sleep 1; done

How to prevent it

  • Provide a valid DATABASE_URL to every step that uses Prisma.
  • Generate the client with correct binaryTargets before running.
  • Gate app start on database readiness in CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →