sindresorhus/got · error · Error
Using UNIX domain sockets but option `enableUnixSockets` is
Error message
Using UNIX domain sockets but option `enableUnixSockets` is not enabled
What it means
Thrown when the resolved URL references a UNIX domain socket (e.g. `http://unix:/var/run/docker.sock:/path`) but the `enableUnixSockets` option is not set to `true`. UNIX socket support is opt-in because it has security and parsing implications, so Got makes you acknowledge it explicitly.
Source
Thrown at source/core/options.ts:2130
is.string(value)
&& !this.prefixUrl
&& hasHttpProtocolWithoutSlashes(valueString)
) {
throw new Error('`url` protocol must be followed by `//`');
}
// Detect if URL is already absolute.
const isAbsolute = isAbsoluteUrl(value);
assertRelativeUrlIfNeeded(this, value);
// Only concatenate prefixUrl if the URL is relative
const urlString = isAbsolute ? valueString : `${this.prefixUrl as string}${valueString}`;
const url = new URL(urlString);
this.#internals.url = url;
trackStateMutation(this.#trackedStateMutations, 'url');
if (usesUnixSocket(url) && !this.#internals.enableUnixSockets) {
throw new Error('Using UNIX domain sockets but option `enableUnixSockets` is not enabled');
}
if (url.protocol === 'unix:') {
url.href = `http://unix${url.pathname}${url.search}`;
}
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
const error: NodeJS.ErrnoException = new Error(`Unsupported protocol: ${url.protocol}`);
error.code = 'ERR_UNSUPPORTED_PROTOCOL';
throw error;
}
if (this.#internals.username) {
url.username = this.#internals.username;
this.#internals.username = '';
}
View on GitHub (pinned to e3924aa1e5)
Solutions
- Enable the feature: `got(url, {enableUnixSockets: true})` or set it via `got.extend({enableUnixSockets: true})`.
- Verify the socket URL uses the `http://unix:<path>:<request-path>` form Got expects.
- If you did not intend a socket, fix the URL hostname.
Example fix
// before
await got('http://unix:/var/run/docker.sock:/info');
// after
await got('http://unix:/var/run/docker.sock:/info', {enableUnixSockets: true}); Defensive patterns
Strategy: validation
Validate before calling
function assertUnixSocketEnabled(url, options) {
const isUnix = typeof url === 'string' && /unix:/.test(url);
if (isUnix && !options?.enableUnixSockets) {
throw new Error('Pass {enableUnixSockets: true} for UNIX socket URLs.');
}
} Type guard
function isUnixSocketUrl(v: unknown): boolean {
return typeof v === 'string' && /\/\/unix:|unix:/.test(v);
} Prevention
- Centralize UNIX-socket calls in a `got.extend({enableUnixSockets: true})` instance.
- Document the socket URL format your code expects.
When it happens
Trigger: Calling `got('http://unix:/var/run/docker.sock:/info')` without `{enableUnixSockets: true}`, or any URL whose hostname resolves to a socket path while `enableUnixSockets` is at its default of `false`.
Common situations: Talking to the Docker API, a local Postgres/Redis socket, or any service over a `.sock` file; copying a curl UNIX-socket URL into Got without enabling the option.
Related errors
- `url` must not start with a slash
- `url` protocol must be followed by `//`
- Invalid DNS lookup IP version: ${value as string}
- The maximum acceptable retry noise is +/- 100ms, got ${value
- Parameters `path` and `pathname` are mutually exclusive.
AI-assisted analysis of sindresorhus/got@e3924aa1e5 (2026-08-03).
Data as JSON: /data/errors/a35f6014e046f664.json.
Report an issue: GitHub.