denoland/deno · error · TypeError

Unsupported 'alpnProtocols' option provided. 'h2' and 'http/

Error message

Unsupported 'alpnProtocols' option provided. 'h2' and 'http/1.1' are automatically supported.

What it means

Some environments (notably Node's TLS APIs) let callers configure ALPN protocol negotiation. Deno's Hyper-based HTTP server always negotiates h2 and http/1.1 automatically over TLS, so the alpnProtocols option is not supported; passing it throws this TypeError at startup to make the unsupported surface explicit.

Source

Thrown at ext/http/00_serve.ts:1374

      automaticCompression,
    );
  }

  const listenOpts = {
    hostname: options.hostname ?? "0.0.0.0",
    port: options.port ?? 8000,
    reusePort: options.reusePort ?? false,
    loadBalanced: options[kLoadBalanced] ?? false,
    tcpBacklog: options.tcpBacklog,
  };

  if (options.certFile || options.keyFile) {
    throw new TypeError(
      "Unsupported 'certFile' / 'keyFile' options provided: use 'cert' / 'key' instead.",
    );
  }
  if (options.alpnProtocols) {
    throw new TypeError(
      "Unsupported 'alpnProtocols' option provided. 'h2' and 'http/1.1' are automatically supported.",
    );
  }

  let listener;
  if (wantsHttps) {
    if (!options.cert || !options.key) {
      throw new TypeError(
        "Both 'cert' and 'key' must be provided to enable HTTPS",
      );
    }
    listenOpts.cert = options.cert;
    listenOpts.key = options.key;
    listenOpts.alpnProtocols = ["h2", "http/1.1"];
    listener = listenTls(listenOpts);
    listenOpts.port = listener.addr.port;
  } else {
    listener = listen(listenOpts);

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Delete the alpnProtocols option; h2 and http/1.1 are already supported automatically
  2. If you depended on restricting protocols, note that Deno does not expose ALPN selection and serves both
  3. Keep cert/key for TLS and drop all Node-only TLS options when migrating

Example fix

// before
Deno.serve({
  port: 443,
  cert,
  key,
  alpnProtocols: ["h2", "http/1.1"], // unsupported option
  handler,
});

// after
Deno.serve({ port: 443, cert, key, handler }); // ALPN negotiated automatically
Defensive patterns

Strategy: validation

Validate before calling

// Strip unsupported TLS options before serving
function stripUnsupportedTls(o) {
  const { alpnProtocols: _ignored, ...rest } = o;
  return rest;
}
Deno.serve(stripUnsupportedTls({ ...options, handler }));

Type guard

function hasUnsupportedTlsOptions(o) {
  return "alpnProtocols" in o;
}

Prevention

When it happens

Trigger: Including alpnProtocols: ['h2', 'http/1.1'] (or any value) in the serve options when enabling HTTPS with cert/key.

Common situations: Porting Node.js https.createServer TLS options verbatim to Deno.serve; config templates that carry Node-style ALPN lists.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/6dc2e678962b8c66. Report an issue: GitHub.