I'm trying to use Prisma in my NestJS project. Prisma initializes correctly, but whenever I run any Prisma CLI command (e.g., npx prisma, npx prisma migrate dev, etc.), I get this error:
Failed to load config file "D:\coding\backend-development\nestjs-blog-api" as a TypeScript/JavaScript module.
Error: PrismaConfigEnvError: Missing required environment variable: DATABASE_URL
I already created a .env file in the project root and set the DATABASE_URL variable correctly. NestJS can read the environment variable without any issues — only Prisma CLI is failing.
My file structure:
project-root/
prisma/
schema.prisma
.env
package.json
...
.env contains:
DATABASE_URL="postgresql://user:pass@localhost:5432/mydb?schema=public"
I also tried:
Restarting the terminal
Running Prisma commands with
--schemaChecking for casing issues
Deleting and recreating
.env
But the error still appears.
What am I missing? How can I fix Prisma not detecting the .env file?
.envfile, include reproducible code