knex/knex · critical · Error

knex: Required configuration option 'client' is missing.

Error message

knex: Required configuration option 'client' is missing.

What it means

Thrown in the Client constructor when neither `config.client` nor a dialect-assigned `this.dialect` is present. Knex needs a client name to know which dialect (mssql, postgres, mysql2, sqlite3, etc.) to load and how to build SQL. Without it the instance cannot resolve a driver, formatter, or pool, so construction aborts immediately.

Source

Thrown at lib/client.js:78

    this.logger = new Logger(this.config);

    if (this.config.connection && config.connection.password) {
      setHiddenProperty(this.config.connection, config.connection);
    }

    //Client is a required field, so throw error if it's not supplied.
    //If 'this.dialect' is set, then this is a 'super()' call, in which case
    //'client' does not have to be set as it's already assigned on the client prototype.

    if (this.dialect && !this.config.client) {
      this.logger.warn(
        `Using 'this.dialect' to identify the client is deprecated and support for it will be removed in the future. Please use configuration option 'client' instead.`
      );
    }

    const dbClient = this.config.client || this.dialect;
    if (!dbClient) {
      throw new Error(
        `knex: Required configuration option 'client' is missing.`
      );
    }

    if (config.version) {
      this.version = config.version;
    }

    if (this.config.connection && this.config.connection instanceof Function) {
      this.connectionConfigProvider = this.config.connection;
      this.connectionConfigExpirationChecker = () => true; // causes the provider to be called on first use
    } else {
      this.connectionSettings = cloneDeepWith(
        this.config.connection || {},
        preserveClassInstances
      );
      if (config.connection && config.connection.password) {
        setHiddenProperty(this.connectionSettings, this.config.connection);

View on GitHub (pinned to e25d54bcb7)

Solutions

  1. Add a valid `client` to your config, e.g. `knex({ client: 'postgres', connection: {...} })`.
  2. Verify the value is one of the supported names: mssql, postgres (alias pg/postgresql), mysql/mysql2, mariadb, sqlite3, better-sqlite3, oracledb, cockroachdb, redshift, pgnative.
  3. If the value comes from an env var, confirm it is exported in the running environment and fail fast at boot if it is empty (set a default or throw a clear error).
  4. Check for typos like `client:` vs `clients:`, or nesting `client` inside `connection`.

Example fix

// before
const db = knex({ connection: { host: 'localhost' } });
// after
const db = knex({ client: 'postgres', connection: { host: 'localhost' } });
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED = ['mssql','postgres','pg','postgresql','mysql','mysql2','mariadb','sqlite3','sqlite','better-sqlite3','oracledb','cockroachdb','redshift','pgnative'];
function makeKnex(cfg) {
  if (!cfg || !SUPPORTED.includes(String(cfg.client).trim().toLowerCase())) {
    throw new Error(`Invalid or missing Knex 'client': ${cfg && cfg.client}`);
  }
  return require('knex')({ ...cfg, client: String(cfg.client).trim().toLowerCase() });
}

Type guard

function isKnexClientConfig(c) {
  return c != null && typeof c === 'object' && typeof c.client === 'string' && c.client.trim().length > 0;
}

Prevention

When it happens

Trigger: Calling `knex({ connection: {...} })` (or `new Client({})`) with no `client` key; typoing the key as `clients`/`dialect`/`adapter`; passing a falsy `client` value (`null`, `''`, `undefined`); building Knex config dynamically from an env var that resolved to undefined (e.g. `client: process.env.DB_CLIENT` when unset).

Common situations: Missing/typo'd DB_CLIENT env var in a deployed service; copying a config snippet but deleting the `client:` line; upgrading a starter template that renamed the option; loading config from a JSON/YAML file whose top-level `client` key was nested under `connection`.

Related errors


AI-assisted analysis of knex/knex@e25d54bcb7 (2026-08-03). Data as JSON: /data/errors/a0b79d9ee1e36f40.json. Report an issue: GitHub.