{"id":"be58ad1e3cd00a76","repo":"sidorares/node-mysql2","slug":"ssl-profile-must-be-an-object-instead-it-s-a-ty","errorCode":null,"errorMessage":"SSL profile must be an object, instead it's a ${typeof this.ssl}","messagePattern":"SSL profile must be an object, instead it's a (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/connection_config.js","lineNumber":166,"sourceCode":"        ? ConnectionConfig.getSSLProfile(options.ssl)\n        : options.ssl || false;\n    this.multipleStatements = options.multipleStatements || false;\n    this.rowsAsArray = options.rowsAsArray || false;\n    this.namedPlaceholders = options.namedPlaceholders || false;\n    this.nestTables =\n      options.nestTables === undefined ? undefined : options.nestTables;\n    this.typeCast = options.typeCast === undefined ? true : options.typeCast;\n    this.disableEval = Boolean(options.disableEval);\n    this.enableCleartextPlugin = Boolean(options.enableCleartextPlugin);\n    if (this.timezone[0] === ' ') {\n      // \"+\" is a url encoded char for space so it\n      // gets translated to space when giving a\n      // connection string..\n      this.timezone = `+${this.timezone.slice(1)}`;\n    }\n    if (this.ssl) {\n      if (typeof this.ssl !== 'object') {\n        throw new TypeError(\n          `SSL profile must be an object, instead it's a ${typeof this.ssl}`\n        );\n      }\n      // Default rejectUnauthorized to true\n      this.ssl.rejectUnauthorized = this.ssl.rejectUnauthorized !== false;\n    }\n    this.maxPacketSize = 0;\n    this.charsetNumber = options.charset\n      ? ConnectionConfig.getCharsetNumber(options.charset)\n      : options.charsetNumber || Charsets.UTF8MB4_UNICODE_CI;\n    this.compress = options.compress || false;\n    this.authPlugins = options.authPlugins;\n    this.authSwitchHandler = options.authSwitchHandler;\n    this.clientFlags = ConnectionConfig.mergeFlags(\n      ConnectionConfig.getDefaultFlags(options),\n      options.flags || ''\n    );\n    // Default connection attributes","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/sidorares/node-mysql2/blob/5ebe8903d6aea2d8ea1490e11b52491526e50f19/lib/connection_config.js#L148-L184","documentation":"After resolving the `ssl` config option (a string profile name is looked up and returns an object; any other truthy value is used as-is), mysql2 requires the result to be an object. If `options.ssl` is truthy but not an object (e.g. the boolean `true`, a number, or an array), it throws. mysql2's SSL option must be either a string naming a built-in profile, an object of TLS options, or falsy.","triggerScenarios":"Passing `ssl: true` (accepted by some other MySQL libraries like `mysql`/`mysqljs`, but not by mysql2). Or passing a number or array. The value `true` becomes `this.ssl = true` and then fails the `typeof !== 'object'` check.","commonSituations":"Migrating code from the old `mysql` package which accepts `ssl: true`; setting `ssl: true` after reading a generic Node+MySQL tutorial; environment-driven config that resolves to a boolean.","solutions":["Pass an object of TLS options, e.g. `ssl: { rejectUnauthorized: true }`.","Or pass a string naming a built-in SSL profile if one fits.","To disable SSL explicitly, set `ssl: false` or omit it."],"exampleFix":"// before\nmysql.createConnection({ host, user, password, ssl: true });\n\n// after\nmysql.createConnection({ host, user, password, ssl: { rejectUnauthorized: true } });","handlingStrategy":"validation","validationCode":"function normalizeSsl(ssl) {\n  if (ssl === true || (ssl != null && typeof ssl !== 'object' && typeof ssl !== 'string')) {\n    throw new TypeError('mysql2 ssl must be a string profile name or a TLS options object, not ' + typeof ssl);\n  }\n  return ssl;\n}","typeGuard":"function isValidSslOption(ssl) {\n  return ssl == null || typeof ssl === 'string' || (typeof ssl === 'object' && !Array.isArray(ssl));\n}","tryCatchPattern":null,"preventionTips":["Never pass `ssl: true` to mysql2; pass a TLS options object instead.","Centralise connection-config construction behind a validated factory.","When migrating from the `mysql` package, replace `ssl: true` with `ssl: {}`."],"tags":["ssl","connection-config","tls"],"analyzedSha":"5ebe8903d6aea2d8ea1490e11b52491526e50f19","analyzedAt":"2026-08-03T18:58:53.602Z","schemaVersion":2}