Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set environment variables with Prisma, Nextjs, and Vercel

Tags:

next.js

prisma

Nextjs wants you to use a .env.local file to store env vars. Prisma uses .env

If I use a .env.local file then setting up the Prisma db

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

I get a DATABASE_URL does not exist error.

What's the right way to set up env vars for a Prisma, Nextjs, Vercel app?

like image 607
grabury Avatar asked Jan 29 '26 07:01

grabury


1 Answers

You can use dotenv-cli to force loading specific environment file.

1- Install dotenv-cli package

2- create script to run env before prisma migration on your package

"scripts": {
    ...
    "prismaDev": "dotenv -e .env.local prisma migrate dev ",
  }

3- now you can simply run npm run prismaDev

like image 174
Chemi Adel Avatar answered Feb 02 '26 21:02

Chemi Adel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!