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

PromisePool.query() validates its second argument at pool.js:41 and throws synchronously if it is a function. A pool obtained via createPool(...).promise() or require('mysql2/promise').createPool() exposes only the promise-based query; a node-style callback is not accepted.

Source

Thrown at lib/promise/pool.js:42

      corePool.getConnection((err, coreConnection) => {
        if (err) {
          reject(err);
        } else {
          resolve(new PromisePoolConnection(coreConnection, this.Promise));
        }
      });
    });
  }

  releaseConnection(connection) {
    if (connection instanceof PromisePoolConnection) connection.release();
  }

  query(sql, args) {
    const corePool = this.pool;
    const stackHolder = captureStackHolder(PromisePool.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);
      if (args !== undefined) {
        corePool.query(sql, args, done);
      } else {
        corePool.query(sql, done);
      }
    });
  }

  execute(sql, args) {
    const corePool = this.pool;
    const stackHolder = captureStackHolder(PromisePool.prototype.execute);
    if (typeof args === 'function') {
      throw new Error(

View on GitHub (pinned to 5ebe8903d6)

Solutions

  1. Await the promise: const [rows] = await pool.query('SELECT 1')
  2. Pass params as an array: await pool.query('SELECT ? FROM t', [col])
  3. If you truly need callbacks, import from 'mysql2' (not 'mysql2/promise') and skip .promise()

Example fix

// before
const mysql = require('mysql2/promise');
const pool = mysql.createPool({});
pool.query('SELECT 1', (err, rows) => {}); // throws

// after
const [rows] = await pool.query('SELECT 1');
Defensive patterns

Strategy: type-guard

Validate before calling

function promisePoolQuery(pool, sql, params) {
  if (typeof params === 'function') {
    throw new TypeError('mysql2 promise pool: do not pass a callback to query(); await the result');
  }
  return params !== undefined ? pool.query(sql, params) : pool.query(sql);
}

Type guard

function isCallbackArg(arg) {
  return typeof arg === 'function';
}

Try / catch

try {
  const [rows] = await pool.query('SELECT 1');
} catch (err) {
  // synchronous throw: wrap must cover the call itself
  console.error(err);
}

Prevention

When it happens

Trigger: Calling pool.promise().query('SELECT 1', cb), or pool.query('SELECT 1', cb) on a pool from mysql2/promise. Also when refactoring callback code and leaving the callback in the args position.

Common situations: Mixing require('mysql2') (callback) with require('mysql2/promise') (promise) in the same codebase, or copy-pasting callback examples from docs into a promise-based project.

Related errors


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