Skip to content
Nilay Kabariya

Entry No.117·Database··2 min read

SASL: "client password must be a string" (node-postgres)

node-postgres throws this before Postgres checks the password: the password it got is not a string. Eight ways to cause it, tested with pg 8.23.1, and the fix.

by Nilay#postgres#node#sequelizeDATABASE

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.js
Not 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

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.js

Or 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

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.078

    Postgres password authentication failed (password is right)

    Changed POSTGRES_PASSWORD in docker-compose and the old one still works? The volume keeps it. Five causes of this Postgres error, reproduced with postgres:18.

    > psql: error: connection to server at "localhost" (::1), port 5432 failed: FATAL: password authentication failed for user "postgres"

    DATABASE5 min
  2. No.054

    Drizzle "Failed query" error: find the real cause

    Drizzle shows the SQL and params but not why it failed. Five causes reproduced, why e.code stopped working in 0.44, and the migration version.

    > DrizzleQueryError: Failed query: insert into "users" ("id", "email", "name") values (default, $1, $2)

    DATABASE4 min
  3. No.079

    Prisma P2002 on Prisma 7: e.meta.target is now undefined

    On Prisma 7, P2002 names the constraint on Postgres and e.meta.target is undefined on Postgres and SQLite. Where the field went, and the upsert race.

    > PrismaClientKnownRequestError:

    DATABASE4 min

tip: paste the exact error text