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

  1. Use one of the valid transports: http, https, socks5, tcp, unix, vsock
  2. If you wanted a SOCKS5h proxy, keep transport: "socks5" and put socks5h: in the url
  3. 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

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


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)