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.
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
- Read the message under PrismaClientInitializationError.
- For a URL error, set a valid
DATABASE_URLin the step env. - For an engine error, verify binaryTargets and that generate ran.
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/appWait for the database before connecting
Ensure the database service is accepting connections before the app or tests construct the client.
until pg_isready -h localhost -p 5432; do sleep 1; doneHow 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.