sindresorhus/got · error · TypeError
Invalid DNS lookup IP version: ${value as string}
Error message
Invalid DNS lookup IP version: ${value as string} What it means
Thrown by the `dnsLookupIpVersion` setter when the value is anything other than `undefined`, `4`, or `6`. The option pins DNS resolution to an IP family and only those three values are meaningful, so any other input (a string like `'ipv4'`, a boolean, or a wrong number) is rejected.
Source
Thrown at source/core/options.ts:2948
}
/**
Indicates which DNS record family to use.
Values:
- `undefined`: IPv4 (if present) or IPv6
- `4`: Only IPv4
- `6`: Only IPv6
@default undefined
*/
get dnsLookupIpVersion(): DnsLookupIpVersion {
return this.#internals.dnsLookupIpVersion;
}
set dnsLookupIpVersion(value: DnsLookupIpVersion) {
if (value !== undefined && value !== 4 && value !== 6) {
throw new TypeError(`Invalid DNS lookup IP version: ${value as string}`);
}
this.#internals.dnsLookupIpVersion = value;
}
/**
A function used to parse JSON responses.
@example
```
import got from 'got';
import Bourne from '@hapi/bourne';
const parsed = await got('https://example.com', {
parseJson: text => Bourne.parse(text)
}).json();
console.log(parsed);View on GitHub (pinned to e3924aa1e5)
Solutions
- Pass one of `undefined`, `4`, or `6` (numbers, not strings).
- If the value comes from config/env, coerce explicitly: `Number(value)` and validate before passing.
- Map labels to numbers: `{ipv4: 4, ipv6: 6}[label]`.
Example fix
// before
await got(url, {dnsLookupIpVersion: 'ipv4'});
// after
await got(url, {dnsLookupIpVersion: 4}); Defensive patterns
Strategy: type-guard
Validate before calling
function normalizeDnsVersion(value) {
const map = {ipv4: 4, ipv6: 6, 4: 4, 6: 6, undefined};
const v = map[value] ?? value;
if (v !== undefined && v !== 4 && v !== 6) {
throw new TypeError(`dnsLookupIpVersion must be undefined, 4, or 6; got ${value}`);
}
return v;
} Type guard
function isDnsLookupIpVersion(v: unknown): v is undefined | 4 | 6 {
return v === undefined || v === 4 || v === 6;
} Prevention
- Pass numbers (`4`/`6`), never string labels.
- Coerce env/config values with `Number()` and validate before passing.
When it happens
Trigger: Calling `got(url, {dnsLookupIpVersion: 'ipv4'})`, `{dnsLookupIpVersion: 4.0}`, `{dnsLookupIpVersion: true}`, or any value that is not exactly `undefined`, `4`, or `6`.
Common situations: Passing a string label (`'ipv4'`/`'ipv6'`) instead of the numeric family; passing a stringified number from env vars or config files.
Related errors
- The maximum acceptable retry noise is +/- 100ms, got ${value
- Unexpected option: ${key}
- Unexpected agent option: ${key}
- Unexpected timeout option: ${key}
- Using UNIX domain sockets but option `enableUnixSockets` is
AI-assisted analysis of sindresorhus/got@e3924aa1e5 (2026-08-03).
Data as JSON: /data/errors/0acf834c5b2d61c3.json.
Report an issue: GitHub.