Error when attempting to migrate on Windows
Hey, I am working on a project which uses Next.js, TypeScript and Drizzle, I'm running a local, freshly installed Postgres server on my machine, in which I have created a database and granted all permissions for it to user
postgres
. I am getting a connection URL from the environment variables (specified in a .env.local
file) in the following format: postgres://postgres:[email protected]:5432/<db_name>
.
The error I'm getting is this:
Postgres logs show me the following:
My drizzle.config.ts
looks like this:
I have verified that the environment variable for the URL is being pulled correctly. The weird thing is, I get the exact same setup working without issues on my macOS machine.11 Replies
Did you forget to put the user and password in your connection string?
No, as can be seen in quite the beginning of my original post, the connection URL stored as an environment variable is formatted as
postgres://postgres:[email protected]:5432/<db_name>
, meaning the user and password both are postgres
I see. The issue might be that you shouln'd provide a connection string, but credentials in form of an object with user, password properties
That is not the case. I have tested that exact potential solution, but to no avail.
There are different answers there, hopefully one can help you https://stackoverflow.com/questions/69878173/scram-server-first-message-client-password-must-be-a-string
Stack Overflow
SCRAM-SERVER-FIRST-MESSAGE: client password must be a string
Ive read documentation from several pages on SO of this issue, but i havent been able to fix my issue with this particular error.
throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client passw...
I have previously checked all of the fixes suggested in that article, none of them have fixed my issue.
When I change the authentication method for the Postgres server, I am also getting an wrror which tells me "Authentication failed for user '<my local system username>". This makes me wonder if something is wrong with my server config. Why does it try to connect using my local account username, when I have specifically provided a connection string which uses 'postgres' as the username? I have no idea and none of the online resources seem to answer this question either. The behaviour is the same on Linux. I have tried a clean install on macOS as well, and there the behaviour is different. Everything works as expected out of the box. I have also tried copying over the server config files (specifically pg_hba.conf and pg_ident.conf), but this does not change anything.
I’ve never had this problem, so I honestly don’t know. Then again I’ve never use connection strings. I use objects
Problem was elsewhere - Next.js environment variable handling intricacies. Thanks for help anyways, @Angelelz!
Please share
guess trying to use DATABASE_URL in client side so its undefined since its not NEXT_PUBLIC
or const { DATABASE_URL } = process.env this is being run at run time, in which case you cant destructure process.env in nextjs
That’s probably why I haven’t seen those problems, because I’ve never done those things lol