GeezerVison is showing github.com — Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string · Issue #2757 · brianc/node-postgres
Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string #2757DescriptionReacted by bever1337, Jaime Leonardo Suncin Cruz, Alex Galhardo, 0shape, Mohammad, Soumya Deep Sarkar, Fedu, Vaggelis Manousakis and Nick Clyde Activityyuneda commented on Jun 7, 2022 if (typeof password !== 'string') {
throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string')
}
sehrope commented on Jun 7, 2022 Is there a question or issue? That check was added to the SASL code to provide the end user with a more informative error message rather than just failing due to the password being null / undefined. yuneda commented on Jun 7, 2022 I'm using jest and supertest for testing my express APIs with Postgre.
The error comes from my code below.
const app = require('../../app');
const request = require('supertest');
let agent = request.agent(app);
describe('Cars', function () {
it('Get all car', (done) => {
agent
.get('/v1/cars')
.expect('Content-Type', /json/)
.then((response) => {
expect(response.status).toEqual(200);
});
done();
});
});
sehrope commented on Jun 7, 2022 You're probably running your tests without the database password available to the test environment.
If you're having an actual issue with this library then provide a self contained example that reproduces it. Reacted by bever1337 and Abhishek Prajapati alexianaa commented on Jul 20, 2022 I changed the password using:
$ sudo passwd postgres
new password:
password again:
$ su postgres
remember change the password at the file
Reacted by Marcus Martins, Luan Melo, Iago Campelo and Thyago Henrique Moura dos Anjos Reacted by Nguyễn Văn Tuấn, fabrotec, Javohir Muhammadiyev, Carlos Peñaloza, jkazimierczak, Anya Rajan, Daniel Osvaldo Rahmanto, Rafa, SlipknoteDark, Ammar and 5 more sehrope commented on Aug 1, 2022 @Quintinius The "localhost" in that connection URI would connect over TCP, not a unix socket. Check your pg_hba to see if TCP connections are requiring SASL. It's probably only local unix socket connections that are password-less. bever1337 commented on Aug 20, 2022 Here is a minimal reproduction:
# .env
PGDATABASE=blahblahblah
PGUSER=blahblahblah
{
"name": "example reproduction",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "UNLICENSED",
"dependencies": {
"dotenv": "^16.0.1",
"pg": "^8.7.3"
}
}
const { Pool } = require('pg');
const dotenv = require('dotenv');
dotenv.config();
async function main() {
const pool = new Pool();
const client = await pool.connect();
client.release();
}
main();
Environment requirements are a database, a database user, and no required database password. Observe that the script exits after some time in v16.14.0 but throws the SASL error in v18.7.0. Guarantee the password parameter is an empty string in both input options and .env files and observe no change in behavior.
I am assuming there is a breaking change with a NodeJS data type.
I've been using a database without a password for local testing and development. The database is only available on the local machine. node-postgres has been working fine in another project. I upgraded the node runtime to v18 so I could make use of experimental global Request/Response interfaces and can no longer use pg. Bummer! I hope this helps.
When I add a password blahblahblah to user blahblahblah, the script works as-expected regardless of node runtime. Reacted by Omer Oran, Ran Halprin and Spase Markovski Vlado-99 commented on Sep 15, 2022
Is there a question or issue?
It is not possible to connect to database using connectionString anymore, if the database account is without password.
This is a breaking change, issue.
The problem - in my specific case - was outside this library. Sorry for noise. rhewy commented on Nov 20, 2022 If a blank password is sent to the postgreSQL server then and error is thrown
throw new Error('SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string')
The error is very special; not caught by .catch on the client promise and not caught with a try catch rhewy commented on Nov 20, 2022 Port can be blank --> defaults to 5432
Username can be blank --> defaults to the OS username
Host can be blank --> defaults to localhost
Just a blank password caused the problem rhewy commented on Nov 20, 2022 This seemed to help; if the password is blank/empty set it to a single space
var connConfig = {
host: req.body.host,
port: req.body.port,
database: req.body.database,
user: req.body.username,
password: req.body.password
};
connConfig.password = connConfig.password.length == 0 ? " " : connConfig.password
rhewy commented on Nov 20, 2022 Nikire commented on Dec 25, 2022 Hi ! just want to share my solution, I was getting this error by badly importing some models and using them before I sync the server
The way I was importing the models :
const { models: { User, Post } } = require('../sequelize');
The problem was that I was importing the models and using it directly in a helpers/utils/functions file,
and then I solve it by passing the models through parameters :
async findPostAndUser(postId, userId, Post, User) {
const post = await Post.findOne({ where: { id: { [Op.eq]: postId } } });
const user = await User.findOne({ where: { id: { [Op.eq]: userId } } });
return [post, user];}
jgoux commented on Jan 19, 2023 We are hitting this issue too, any password-protected database receiving a connection string with an empty password is raising this error.
I absolutely have no clue why we can't catch this error, this is actually my main issue. Does anyone know why it's not possible to catch this one? 😅 rhewy commented on Jan 19, 2023 jean-pita commented on Dec 19, 2023 I'm using typeorm and I had to export an environment variable with the database connection string:
export DATABASE_URL=postgres://postgres:postgres@localhost:5432/default
shuvo-halder commented on Dec 8, 2024 rhewy commented on Dec 8, 2024 Your password is blank/null. Somewhere you need to set it. Kartagia commented on May 10, 2025 Postgresql allows empty password strings, but the library does not. The problem is that somewhere in the node-postgresql code someone uses test if (password) { set password } instead of if(password !== undefined) as they should. The problem is stupidity not doing tests properly, but lazily. Kartagia commented on May 10, 2025 Found cause of this problem. It is as I expected, the stupid lazy testing with falsy instead of undefined.
Package: pg
Location: packages/pg/lib/connection-parameters.js
Function: vars (lines 8 -12)
const val = function (key, config, envVar) {
if (envVar === undefined) {
envVar = process.env['PG' + key.toUpperCase()]
} else if (envVar === false) {
// do nothing ... use false
} else {
envVar = process.env[envVar]
}
return config[key] || envVar || defaults[key]
}
The return clause uses falsy testing instead of testing undefinedness. This is not how testing should be done, if empty strings (or zeros) are allowed as values.
I am trying to figure out how to create fix patch for this, as the fix is simply defining return statement at line 18:
return (configKey[key] ?? envVar) ?? defaults[key]
or with following, if support for older syntax is wanted.
return (configKey[key] == null ? (envVar == null ? defaults[key] : envVar) : configKey[key])
Also the uses pg-connection-string package for parsing connection string assumes all segments of the postgresql query exists, or socket file is used. The latter is NOT show in the documentation pages at all. saatvik-10 commented on Dec 1, 2025 in my case, am using prisma v7 and getting this err....checked everything, both the db url in env and docker pswd are fine still this err
import { PrismaClient } from './generated/prisma/client';
import { PrismaPg } from '@prisma/adapter-pg';
declare global {
var prisma: PrismaClient | undefined;
}
const adapter = new PrismaPg({
connectionString: process.env.DATABASE_URL
});
export const db = globalThis.prisma || new PrismaClient({
adapter
});
if (process.env.NODE_ENV !== 'production') {
globalThis.prisma = db;
} Reacted by Anshu Gahire, ccf19881030.github.io and Khurshid Ernazarov FosRexx commented on Dec 3, 2025
in my case, am using prisma v7 and getting this err....checked everything, both the db url in env and docker pswd are fine still this err
import { PrismaClient } from './generated/prisma/client'; import { PrismaPg } from '@prisma/adapter-pg';
declare global { var prisma: PrismaClient | undefined; }
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
export const db = globalThis.prisma || new PrismaClient({ adapter });
if (process.env.NODE_ENV !== 'production') { globalThis.prisma = db; }
Had the exact same issue. My error was not explicitly passing the connectionString to the PrismaPg adapter, as I incorrectly assumed it would automatically pick it up from the Prisma configuration. Once I explicitly filled in the connectionString with the DATABASE_URL, the error went away. I recommend you double check your DATABASE_URL and ensure you have configured a password for your database user, as some people have found that an empty password field causes this specific adapter issue. Reacted by Khurshid Ernazarov saatvik-10 commented on Dec 7, 2025
the DATABASE_URL, the error went away. I recommend you double ch
still getting the same error....the project is not taking env, just logging undefined (using monorepo) Reacted by Khurshid Ernazarov techforces commented on Dec 17, 2025
Had the exact same issue. My error was not explicitly passing the connectionString to the PrismaPg adapter
Jesus exactly what I was experiencing.
I have .env file where I have declared my DATABASE_URL but I forgot to enable using the .env parameters inside my Prisma.ts file where I was defining the PrismaClient. It was undefined this entire time. Simply adding import "dotenv/config" fixed it. saatvik-10 commented on Dec 18, 2025 the new prisma version already has that still the issue was coming.....imported the env in both web and server and it worked but then it eliminates the meaning of a mono repo in some way......putting env in every folder instead of the package/db only (db connection url) henrybastos commented on Feb 18, 2026 Hi! I'm using NestJS and Prisma and also came across this problem, but I managed to solve it.
In NestJS docs, for a Prisma service, it uses an adapter (which instead of PrismaBetterSqlite3 I was using PrismaPg).
But instead of:
new PrismaPg({ url: process.env.DATABASE_URL });
I did:
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
const adapter = new PrismaPg(pool);
and the problem disappeared :)
System info:
@nestjs/common: "^11.0.0"
@nestjs/core: "^11.0.0"
prisma: "^7.4.0"
pg: "^8.18.0"
@types/pg: "^8.16.0"
@prisma/adapter-pg: "^7.4.0"
@prisma/client: "^7.4.0"
OS: Windows 10
charmander commented on Feb 18, 2026 @henrybastos PrismaPg documentation suggests:
new PrismaPg({ connectionString: process.env.DATABASE_URL })Reacted by Henry Bastos da Silva henrybastos commented on Feb 18, 2026
@henrybastos PrismaPg documentation suggests:
new PrismaPg({ connectionString: process.env.DATABASE_URL })
Oh right! I was using the same url parameter as the PrismaBetterSqlite3, now it makes sense. Thanks
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|