The error, verbatim
Jump to the fix ↓Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string
The fix that worked
Load your .env before the client is created:
node --env-file=.env app.jsNot it? Every cause, tested ↓Tested on
- Postgres
- 17 (official Docker image, scram-sha-256)
- Clients
- pg 8.23.1, Sequelize 6.37.8, dotenv 18.0.10
- Node
- 24.22.2
- Where
- GitHub Actions ubuntu-latest, November 10, 2026
✓ Last re-run on GitHub Actions · see the run · all repros
Contents
This error comes from node-postgres (the pg package), not from Postgres. The server asked for a SCRAM password, and the password pg was given was not a usable string, so it stopped before sending any password proof. Your password isn’t wrong; it never arrived. A common cause is an environment variable that was never loaded.
The fix
Make sure the variable is loaded before the client is created. With a .env file, let Node load it:
node --env-file=.env app.jsOr load it with dotenv as the very first import:
import "dotenv/config";
import pg from "pg";
const client = new pg.Client({ password: process.env.DB_PASSWORD /* ... */ });Eight ways to get it
I ran each of these against a Postgres 17 container with the password 12345, with no PGPASSWORD set:
| What the client was given | Result |
|---|---|
password: process.env.DB_PASSWORD, .env file present but never loaded |
this error |
no password option at all |
this error |
password: 12345 (a number) |
this error |
password: null |
this error |
password: "" (for example DB_PASSWORD= in .env) |
this error |
connectionString: "postgres://postgres@localhost:5432/postgres" (no password in the URL) |
this error |
connectionString: process.env.DATABASE_URL, with DATABASE_URL unset |
this error |
password: async () => process.env.DB_PASSWORD (a function that returns undefined) |
this error |
password: "wrong" |
password authentication failed for user "postgres" |
The last row is there for comparison. A wrong password that is a string reaches the server and gets the server’s own error. Everything else in the table never got that far.
The number and the empty string catch people out because they look like passwords. pg 8.23.1 wanted a non-empty string: String(12345) connected where 12345 didn’t. An empty value usually means the variable exists in .env with nothing after the =.
Pool and Sequelize give the same message
A pg.Pool failed in the same way, on its first query. Sequelize uses pg underneath, so sequelize.authenticate() with an undefined password threw ConnectionError: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string. The fix is the same: load the variable before the Sequelize instance is created.
Other fixes that worked
Test setup
GitHub Actions ubuntu-latest, November 10, 2026, with the postgres:17 image as a service container (password 12345) and Node 24.22.2. The packages were the newest on npm that day: pg 8.23.1, Sequelize 6.37.8, dotenv 18.0.10. PGPASSWORD, DB_PASSWORD and DATABASE_URL were unset before the cases ran, and a .env with DB_PASSWORD=12345 sat in the folder. Each case opened its own client. Run 42825316672, script.
— N.K., end of entry No.117