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

  1. Await the promise: const [rows] = await poolCluster.query('SELECT 1')
  2. Pass values as an array: await poolCluster.query('SELECT ? FROM t', [col])
  3. 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

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


AI-assisted analysis of sidorares/node-mysql2@5ebe8903d6 (2026-08-03). Data as JSON: /data/errors/68c41be5c41e41c6.json. Report an issue: GitHub.