prisma: Prisma edge client can't read env vars from `.env` file
Bug description
When I import “@prisma/client” it reads my env vars (e.g. DATABASE_URL).
Using the same .env file, when I import “@prisma/client/edge” it can’t read them anymore and I get
InvalidDatasourceError: Datasource "db" references an environment variable "DATABASE_URL" that is not set
This is the local dev server for a sveltekit app, so not even trying to deploy it yet.
The schema code that reads env looks like this:
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
// directUrl = env("DIRECT_URL")
relationMode = "prisma"
}
How to reproduce
Create sveltekit skeleton project
Verify it works
Add prisma, a schema (reads DATABASE_URL
from env) with a table, and a row of data (mysql planetscale db)
Add a .env file with the database url string
Verify you can query the database and run the local dev server, see the data in the page
Change to the prisma edge client
You’ll see the error above
Expected behavior
No response
Prisma information
Relevant parts of schema already provided
Environment & setup
- OS: Fedora
- Database: PlanetScale
- Node.js version: 18.7.0
Prisma Version
4.10.0
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 15 (6 by maintainers)
The deployment to vercel edge functions now works with the same solution of passing database url env var to the prisma client constructor like this:
But the issue remains for why it’s necessary to do that when switching to the edge client