Environment variables in .env file
I have a .env file
And it seems like prisma is having trouble parsing this, it gives a
Error parsing connection string: invalid port number in database URL.
, I was under the impression that strings should be parsed ok if they are wrapped in quotes, is this not true?2 Replies
You chose to compile with the bot. One moment while I piece together your answer…
The issue you're experiencing is related to how Prisma handles special characters in database connection strings. Based on the error message
Error parsing connection string: invalid port number in database URL
, it appears that the colon (:
) in your password is causing problems with the connection string parsing.
When Prisma parses a connection URL, it expects a specific format, and special characters in passwords need to be URL-encoded, especially characters like :
which have special meaning in URLs (separating the password from the host).
According to the knowledge sources, this is a known issue. When your password contains characters that need URL encoding (like :
), Prisma expects you to provide the encoded parts for the connection string. Simply wrapping the password in quotes isn't sufficient.
As mentioned in a GitHub issue discussion:
Prisma ORM expects you to provide the encoded parts for the connection string. Variable expansion is just about combining different strings to another string - additional logic like encoding certain parts would overload that behavior.GitHub Issue #23125 To fix this issue, you should URL-encode the special characters in your password. For example, the colon (
:
) should be encoded as %3A
. You can either:
1. Directly encode the special characters in your password variable:
2. Or use the fully encoded password directly in the DATABASE_URL instead of using variable expansion.
This is a limitation of how Prisma handles environment variables and connection strings. The variable expansion feature doesn't automatically handle URL encoding of special characters.
I hope this helps resolve your connection issue!
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.The password can contain these special characters, I am now constructing the DB_URL without using variable expansion but it still doesn't work, these are the possible special characters
!#%^&*()-_=+[]{}<>?
ah ir seems that i need to percent encode my password, strange, it seemed to work without in a previous deployment, but maybe i just got absurdly lucky