denoland/deno · error · TypeError
Invalid value for 'proxy.transport' option
Error message
Invalid value for 'proxy.transport' option: ${JSONStringify(proxy.transport)} What it means
Deno.createHttpClient() only accepts proxy.transport values from a fixed set: "http", "https", "socks5", "tcp", "unix", and "vsock". Any other value (including misspellings, "socks4", "socks5h" as a transport, or non-string values) falls into the default branch of the switch and throws this TypeError with the offending value JSON-stringified in the message.
Solutions
- Use one of the valid transports: http, https, socks5, tcp, unix, vsock
- If you wanted a SOCKS5h proxy, keep transport: "socks5" and put socks5h: in the url
- Validate/normalize config values against the allow-list before calling createHttpClient
Example fix
// before
const client = Deno.createHttpClient({
proxy: { url: "socks4://h:1080", transport: "socks4" }, // throws
});
// after
const client = Deno.createHttpClient({
proxy: { url: "socks5://h:1080", transport: "socks5" },
}); Defensive patterns
Strategy: type-guard
Validate before calling
const PROXY_TRANSPORTS = ["http", "https", "socks5", "tcp", "unix", "vsock"];
const t = String(proxy.transport ?? "").toLowerCase();
if (!PROXY_TRANSPORTS.includes(t)) {
throw new Error(`proxy.transport must be one of ${PROXY_TRANSPORTS.join(", ")}, got ${proxy.transport}`);
} Type guard
const PROXY_TRANSPORTS = ["http", "https", "socks5", "tcp", "unix", "vsock"] as const;
export type ProxyTransport = (typeof PROXY_TRANSPORTS)[number];
function isProxyTransport(v: unknown): v is ProxyTransport {
return typeof v === "string" && (PROXY_TRANSPORTS as readonly string[]).includes(v);
} Try / catch
try {
client = Deno.createHttpClient({ proxy });
} catch (err) {
if (err instanceof TypeError && err.message.includes("proxy.transport")) {
// surface a config error with the allow-list, not the raw TypeError
throw new Error("Invalid proxy.transport — allowed: http, https, socks5, tcp, unix, vsock", { cause: err });
}
throw err;
} Prevention
- Type proxy.transport as a union of the six valid literals in TypeScript
- Normalize case before validation — transports are lowercase
- Remember socks5h is a URL scheme, not a transport value
When it happens
Trigger: Deno.createHttpClient({ proxy: { url: "socks4://h:1080", transport: "socks4" } }); transport: "SOCKS5" (uppercase); transport: undefined via an explicit key ({ transport: undefined } triggers ObjectHasOwn); transport: "socks5h" (socks5h is a url scheme, not a transport).
Common situations: Assuming any URL scheme is a valid transport name; typo like "htp" or "sock"; passing an unvalidated config value read from a YAML/JSON file; uppercase values from env vars.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- The url passed into 'proxy.url' has an invalid scheme for…
- fetch failed
- Return value from serve handler must not be an error…
- Blob URL fetch only supports GET method
- Body already consumed
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/e64e1813b9d526f5.
Report an issue: GitHub.
Appendix: source
Thrown at ext/fetch/22_http_client.js:82
const url = proxy.url;
if (
!StringPrototypeStartsWith(url, "socks5:") &&
!StringPrototypeStartsWith(url, "socks5h:")
) {
throw new TypeError(
`The url passed into 'proxy.url' has an invalid scheme for this transport.`,
);
}
proxy.transport = "http";
break;
}
case "tcp":
case "unix":
case "vsock": {
break;
}
default: {
throw new TypeError(
`Invalid value for 'proxy.transport' option: ${
JSONStringify(proxy.transport)
}`,
);
}
}
} else {
proxy.transport = "http";
}
}
const keyPair = loadTlsKeyPair("Deno.createHttpClient", options);
return new HttpClient(
op_fetch_custom_client(
options,
keyPair,
),
);
}View on GitHub (pinned to 9ad36f7a2c)