{"record":{"id":"1d0624f5cee408ca","repo":"denoland/deno","slug":"err-invalid-arg-type-1d0624","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"options.${name}\" property must be one of type string, undefined, or null","messagePattern":"The \"options\\.(.+?)\" property must be one of type string, undefined, or null","errorType":"validation","errorClass":"NodeTypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_http_client.js","lineNumber":424,"sourceCode":"    timestamp: DateNow() / 1000,\n    type: \"Other\",\n    errorText,\n  });\n}\n\nconst kLenientAll = HTTPParser.kLenientAll | 0;\nconst kLenientNone = HTTPParser.kLenientNone | 0;\n\nclass HTTPClientAsyncResource {\n  constructor(type, req) {\n    this.type = type;\n    this.req = req;\n  }\n}\n\nfunction validateHost(host, name) {\n  if (host !== null && host !== undefined && typeof host !== \"string\") {\n    throw new ERR_INVALID_ARG_TYPE(\n      `options.${name}`,\n      [\"string\", \"undefined\", \"null\"],\n      host,\n    );\n  }\n  return host;\n}\n\nfunction emitErrorEvent(request, error) {\n  if (onClientRequestErrorChannel.hasSubscribers) {\n    onClientRequestErrorChannel.publish({\n      request,\n      error,\n    });\n  }\n  // ---- Inspector: Network.loadingFailed ----------------------------------\n  // Fired before the user's `error` listener so DevTools sees the failure\n  // even if the listener throws.","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/_http_client.js#L406-L442","documentation":"validateHost() in the http/https ClientRequest polyfill enforces that options.host and options.hostname are string, undefined, or null. Any other type (number, object, array, boolean) is rejected with ERR_INVALID_ARG_TYPE before the request is built. This mirrors Node's internal validation of the host fields in urlToHttpOptions.","triggerScenarios":"http.request({ host: 12345 }) (port mistakenly passed as host); passing a URL object or parsed URL JSON as host; hostname coming from untyped config or env parsing that yields a number.","commonSituations":"Misreading options where host should be the hostname string and port is separate; deserialized configuration where host was stored as a number; passing { host: new URL(...) } instead of the URL itself as the input argument.","solutions":["Pass host as a string: http.request({ host: 'example.com', port: 12345 })","If the value is dynamic, coerce explicitly: { host: String(config.host) }","Pass a WHATWG URL or URL string as the first argument instead of decomposing it into an options object with typed host fields"],"exampleFix":"// before\nconst req = http.request({ host: 8080, path: '/' });\n\n// after\nconst req = http.request({ host: '127.0.0.1', port: 8080, path: '/' });","handlingStrategy":"validation","validationCode":"function normalizeHost(opts) {\n  for (const k of ['host', 'hostname']) {\n    const v = opts[k];\n    if (v !== null && v !== undefined && typeof v !== 'string') {\n      opts[k] = String(v); // or throw your own config error\n    }\n  }\n}\nnormalizeHost(options);","typeGuard":"function isValidHost(v) { return v === null || v === undefined || typeof v === 'string'; }","tryCatchPattern":"try { http.request(options); } catch (e) { if (e.code === 'ERR_INVALID_ARG_TYPE' && /options\\.(host|hostname)/.test(e.message)) { /* fix config source */ } else throw e; }","preventionTips":["Type request options in TypeScript: host?: string","Validate config once at load, not per request","Prefer URL-string input over hand-built host/port options"],"tags":["http","client","validation","node-compat"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}