{"id":"a0b79d9ee1e36f40","repo":"knex/knex","slug":"knex-required-configuration-option-client-is-mi","errorCode":null,"errorMessage":"knex: Required configuration option 'client' is missing.","messagePattern":"knex: Required configuration option 'client' is missing\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"lib/client.js","lineNumber":78,"sourceCode":"    this.logger = new Logger(this.config);\n\n    if (this.config.connection && config.connection.password) {\n      setHiddenProperty(this.config.connection, config.connection);\n    }\n\n    //Client is a required field, so throw error if it's not supplied.\n    //If 'this.dialect' is set, then this is a 'super()' call, in which case\n    //'client' does not have to be set as it's already assigned on the client prototype.\n\n    if (this.dialect && !this.config.client) {\n      this.logger.warn(\n        `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.`\n      );\n    }\n\n    const dbClient = this.config.client || this.dialect;\n    if (!dbClient) {\n      throw new Error(\n        `knex: Required configuration option 'client' is missing.`\n      );\n    }\n\n    if (config.version) {\n      this.version = config.version;\n    }\n\n    if (this.config.connection && this.config.connection instanceof Function) {\n      this.connectionConfigProvider = this.config.connection;\n      this.connectionConfigExpirationChecker = () => true; // causes the provider to be called on first use\n    } else {\n      this.connectionSettings = cloneDeepWith(\n        this.config.connection || {},\n        preserveClassInstances\n      );\n      if (config.connection && config.connection.password) {\n        setHiddenProperty(this.connectionSettings, this.config.connection);","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/knex/knex/blob/e25d54bcb707714a17f5a5744eba5c4246bb4d1d/lib/client.js#L60-L96","documentation":"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.","triggerScenarios":"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).","commonSituations":"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`.","solutions":["Add a valid `client` to your config, e.g. `knex({ client: 'postgres', connection: {...} })`.","Verify the value is one of the supported names: mssql, postgres (alias pg/postgresql), mysql/mysql2, mariadb, sqlite3, better-sqlite3, oracledb, cockroachdb, redshift, pgnative.","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).","Check for typos like `client:` vs `clients:`, or nesting `client` inside `connection`."],"exampleFix":"// before\nconst db = knex({ connection: { host: 'localhost' } });\n// after\nconst db = knex({ client: 'postgres', connection: { host: 'localhost' } });","handlingStrategy":"validation","validationCode":"const SUPPORTED = ['mssql','postgres','pg','postgresql','mysql','mysql2','mariadb','sqlite3','sqlite','better-sqlite3','oracledb','cockroachdb','redshift','pgnative'];\nfunction makeKnex(cfg) {\n  if (!cfg || !SUPPORTED.includes(String(cfg.client).trim().toLowerCase())) {\n    throw new Error(`Invalid or missing Knex 'client': ${cfg && cfg.client}`);\n  }\n  return require('knex')({ ...cfg, client: String(cfg.client).trim().toLowerCase() });\n}","typeGuard":"function isKnexClientConfig(c) {\n  return c != null && typeof c === 'object' && typeof c.client === 'string' && c.client.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["Read DB_CLIENT from env with a fail-fast default at boot.","Centralize Knex instance creation behind one factory that validates `client`.","Add an integration test that constructs the Knex instance on CI startup."],"tags":["config","initialization","dialect"],"analyzedSha":"e25d54bcb707714a17f5a5744eba5c4246bb4d1d","analyzedAt":"2026-08-03T18:35:32.148Z","schemaVersion":2}