"Missing required environment variable: DATABASE_URL" after Migrating to prisma.config.ts
I'm trying to migrate to the new
prisma.config.ts as outlines here. I'm running into this error.
This error occurs when I run npx prisma generate.
It was perviously working before moving to prisma.config.ts.
prisma.config.ts
prisma client
Prisma
Prisma ORM 6.18.0, Postgres Database Metrics and Config Modernization
Catch up on the lates 6.18.0 release for Prisma ORM and Prisma Postgres.
1 Reply
You chose to compile with the bot. One moment while I piece together your answer…
The error "Missing required environment variable: DATABASE_URL" after migrating to prisma.config.ts is expected behavior. When you use a Prisma config file (prisma.config.ts), Prisma no longer automatically loads environment variables from .env files. You must explicitly load them yourself.
Solution:
Add dotenv to your project and import it at the top of your prisma.config.ts: Why?
As documented, with prisma.config.ts, environment variables from .env files are not loaded automatically. You must use dotenv or another method to load them yourself. This is a documented change and is also discussed in community issues and the official docs [source][source]. Summary of steps: 1. Install dotenv:
Add dotenv to your project and import it at the top of your prisma.config.ts: Why?
As documented, with prisma.config.ts, environment variables from .env files are not loaded automatically. You must use dotenv or another method to load them yourself. This is a documented change and is also discussed in community issues and the official docs [source][source]. Summary of steps: 1. Install dotenv:
npm install dotenv
2. Add import "dotenv/config"; to the top of your prisma.config.ts.
This should resolve the "Missing required environment variable: DATABASE_URL" error when running Prisma CLI commands after migrating to prisma.config.ts.
✅ Great, thanks for letting us know that this solved your question!