sidorares/node-mysql2 · error · Error
Callback function is not available with promise clients.
Error message
Callback function is not available with promise clients.
What it means
PromisePoolCluster.query() (the cluster itself, not a namespace) checks its second argument at promise.js:88 and throws synchronously if it is a function. The promise-based pool cluster API returns a Promise and does not accept node-style callbacks.
Source
Thrown at promise.js:89
corePoolCluster.getConnection(
pattern,
selector,
(err, coreConnection) => {
if (err) {
reject(err);
} else {
resolve(new PromisePoolConnection(coreConnection, this.Promise));
}
}
);
});
}
query(sql, args) {
const corePoolCluster = this.poolCluster;
const stackHolder = captureStackHolder(PromisePoolCluster.prototype.query);
if (typeof args === 'function') {
throw new Error(
'Callback function is not available with promise clients.'
);
}
return new this.Promise((resolve, reject) => {
const done = makeDoneCb(resolve, reject, stackHolder);
corePoolCluster.query(sql, args, done);
});
}
execute(sql, args) {
const corePoolCluster = this.poolCluster;
const stackHolder = captureStackHolder(
PromisePoolCluster.prototype.execute
);
if (typeof args === 'function') {
throw new Error(
'Callback function is not available with promise clients.'
);View on GitHub (pinned to 5ebe8903d6)
Solutions
- Await the promise: const [rows] = await poolCluster.query('SELECT 1')
- Pass values as an array: await poolCluster.query('SELECT ? FROM t', [col])
- Use require('mysql2') and the callback PoolCluster if callbacks are required
Example fix
// before
poolCluster.query('SELECT 1', (err, rows) => {});
// after
const [rows] = await poolCluster.query('SELECT 1'); Defensive patterns
Strategy: type-guard
Validate before calling
function promiseClusterQuery(cluster, sql, args) {
if (typeof args === 'function') {
throw new TypeError('mysql2 promise PoolCluster: do not pass a callback to query(); await the result');
}
return cluster.query(sql, args);
} Type guard
function isCallbackArg(arg) {
return typeof arg === 'function';
} Try / catch
try {
const [rows] = await poolCluster.query('SELECT 1');
} catch (err) {
// synchronous throw; try must wrap the call expression
console.error(err);
} Prevention
- Treat the promise PoolCluster (from mysql2/promise) as promise-only
- Pass args as an array, never a function
- Keep cluster code isolated to avoid mixing with callback examples
When it happens
Trigger: Calling poolCluster.query('SELECT 1', cb) on a cluster from require('mysql2/promise').createPoolCluster(), or passing a function where the values array is expected.
Common situations: Porting callback PoolCluster examples into a promise-based codebase, or mixing the two cluster API surfaces.
Related errors
- Callback function is not available with promise clients.
- Callback function is not available with promise clients.
- Callback function is not available with promise clients.
- You have tried to call .then(), .catch(), or invoked await o
- no Promise implementation available.Use promise-enabled node
AI-assisted analysis of sidorares/node-mysql2@5ebe8903d6 (2026-08-03).
Data as JSON: /data/errors/68c41be5c41e41c6.json.
Report an issue: GitHub.