New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prisma edge client can't read env vars from .env
file
#18542
Comments
I wonder if this is related to #15958 |
I don't even necessarily need a solution to this problem (although I'll take one if you have it). I just need some ways to debug what is going wrong because right now I don't have any ideas besides reading prisma source code, since that's most of the stacktrace. Speaking of stacktrace, here it is:
|
I just created a new sveltekit skeleton project, added prisma with a single table in the schema, confirmed I could query the database (planetscale) with an actual row of data, then switched to the prisma edge client and it stopped working with the same env var error message above. This definitely appears to be a prisma issue with sveltekit/planetscale |
Hi @kelbyfaessler, this issue is indeed a duplicate of #15958, so I would close this new issue and redirect future communications there. This seems to be one possible workaround, but we're currently looking for better solutions. |
Hi @jkomyno, would you mind sharing your reasoning for why you think this is a duplicate? |
A minimal example that reproduces the issue: |
I see no connection to Cloudflare either. The edge Client does not load the |
@janpio it works if I pass the env var to the client constructor like in the CF issue thread. Not sure why that would make a difference, especially for local dev, but it does. Still trying to get deployment to vercel edge functions working (also has errors) |
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 |
I had the same problem, the proposed workaround works, thanks. |
This comment was marked as outdated.
This comment was marked as outdated.
.env
file
This comment was marked as outdated.
This comment was marked as outdated.
@kelbyfaessler I took another look at this, and the explanation is much simpler:
So when using
That means that on Vercel Edge Functions for example the workaround you posted above should not be necessary. |
And to show with your reproduction repository you provided (Thank you!):
First it fails as you describe. Then I install And if I set the value in
So it definitely gets the correct value with the simple, unmodified |
(Closing this issue now as (@kelbyfaessler @ticup Please still let me know if you agree and understand all of this! I just close the issue so we know which ones we actually have to fix something, not to get rid of you.) |
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:
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
Prisma Version
The text was updated successfully, but these errors were encountered: