denoland/deno · error · NodeTypeError
ERR_INVALID_ARG_TYPE
ERR_INVALID_ARG_TYPE
Error message
The "options.${name}" property must be one of type string, undefined, or null What it means
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.
Source
Thrown at ext/node/polyfills/_http_client.js:424
timestamp: DateNow() / 1000,
type: "Other",
errorText,
});
}
const kLenientAll = HTTPParser.kLenientAll | 0;
const kLenientNone = HTTPParser.kLenientNone | 0;
class HTTPClientAsyncResource {
constructor(type, req) {
this.type = type;
this.req = req;
}
}
function validateHost(host, name) {
if (host !== null && host !== undefined && typeof host !== "string") {
throw new ERR_INVALID_ARG_TYPE(
`options.${name}`,
["string", "undefined", "null"],
host,
);
}
return host;
}
function emitErrorEvent(request, error) {
if (onClientRequestErrorChannel.hasSubscribers) {
onClientRequestErrorChannel.publish({
request,
error,
});
}
// ---- Inspector: Network.loadingFailed ----------------------------------
// Fired before the user's `error` listener so DevTools sees the failure
// even if the listener throws.View on GitHub (pinned to 89f33cbef2)
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
Example fix
// before
const req = http.request({ host: 8080, path: '/' });
// after
const req = http.request({ host: '127.0.0.1', port: 8080, path: '/' }); Defensive patterns
Strategy: validation
Validate before calling
function normalizeHost(opts) {
for (const k of ['host', 'hostname']) {
const v = opts[k];
if (v !== null && v !== undefined && typeof v !== 'string') {
opts[k] = String(v); // or throw your own config error
}
}
}
normalizeHost(options); Type guard
function isValidHost(v) { return v === null || v === undefined || typeof v === 'string'; } Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ERR_INVALID_URL
- ERR_UNESCAPED_CHARACTERS
- ERR_INVALID_HTTP_TOKEN
- ERR_HTTP_HEADERS_SENT
- ERR_INVALID_HTTP_TOKEN
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/1d0624f5cee408ca.
Report an issue: GitHub.