{"id":"72bf0c2d6a1d6ec8","repo":"knex/knex","slug":"invalid-clientname-given-clientname-72bf0c","errorCode":null,"errorMessage":"Invalid clientName given: ${clientName}","messagePattern":"Invalid clientName given: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"lib/dialects/index.ts","lineNumber":29,"sourceCode":"  oracledb: () => require('./oracledb'),\n  pgnative: () => require('./pgnative'),\n  postgres: () => require('./postgres'),\n  redshift: () => require('./redshift'),\n  sqlite3: () => require('./sqlite3'),\n});\n\n/**\n * Gets the Dialect object with the given client name or throw an\n * error if not found.\n *\n * NOTE: This is a replacement for prior practice of doing dynamic\n * string construction for imports of Dialect objects.\n */\nexport function getDialectByNameOrAlias(clientName: string) {\n  const resolvedClientName = resolveClientNameWithAliases(clientName);\n  const dialectLoader = dbNameToDialectLoader[resolvedClientName];\n  if (!dialectLoader) {\n    throw new Error(`Invalid clientName given: ${clientName}`);\n  }\n  return dialectLoader();\n}\n","sourceCodeStart":11,"sourceCodeEnd":33,"githubUrl":"https://github.com/knex/knex/blob/e25d54bcb707714a17f5a5744eba5c4246bb4d1d/lib/dialects/index.ts#L11-L33","documentation":"Same as [11] but located in the TypeScript source `lib/dialects/index.ts` (the compiled `.js` is the file actually executed at runtime). It throws in `getDialectByNameOrAlias()` when the resolved client name is not a known dialect. Functionally identical to error [11]; the `.ts` location appears in source maps/IDE stacks.","triggerScenarios":"Same as [11]: unknown/typo'd client name (`'postgre'`, `'mongo'`, `'PG-NATIVE'`), untrimmed/uncased value from config, or an alias not recognized by `resolveClientNameWithAliases`.","commonSituations":"TypeScript project reading the stack trace through source maps; IDE 'Go to definition' landing on the `.ts`; otherwise identical real-world causes as [11].","solutions":["Use a supported client name/alias (postgres/pg/postgresql, mssql, mysql/mysql2, mariadb, sqlite3/sqlite, better-sqlite3, oracledb, cockroachdb, redshift, pgnative).","Normalize the value: trim + lowercase before passing to Knex.","Validate against the supported list at startup.","Treat this the same as [11] — fix the client name in config."],"exampleFix":"// before\nknex({ client: process.env.DB_CLIENT /* 'PostgreSQL ' */ })\n// after\nknex({ client: process.env.DB_CLIENT.trim().toLowerCase() /* 'postgresql' -> postgres */ })","handlingStrategy":"validation","validationCode":"const { SUPPORTED_CLIENTS } = require('knex/lib/constants');\nfunction normalizeClient(name) {\n  const c = String(name || '').trim().toLowerCase();\n  if (!SUPPORTED_CLIENTS.includes(c)) throw new Error(`Unsupported Knex client: '${name}'`);\n  return c;\n}","typeGuard":"function isSupportedClient(name: unknown): name is string {\n  const list = require('knex/lib/constants').SUPPORTED_CLIENTS as string[];\n  return typeof name === 'string' && list.includes(name.trim().toLowerCase());\n}","tryCatchPattern":null,"preventionTips":["Normalize and validate the client name at the TS entry point.","Type the config client field as a union of supported names.","Add a boot-time assertion so bad config fails fast."],"tags":["config","dialect","initialization","typescript"],"analyzedSha":"e25d54bcb707714a17f5a5744eba5c4246bb4d1d","analyzedAt":"2026-08-03T18:35:32.148Z","schemaVersion":2}