Repository navigation
fix(ext/node): satisfy agent-base node:https stack-trace check - #34264
Merged
Merged
Conversation
`agent-base` (used by `@npmcli/agent`, `http-proxy-agent`, etc.) figures out whether a polymorphic agent should behave as https by scanning the current stack for `(https.js:` or `node:https:`. Without a marker the stack only contained our polyfill path (`ext:deno_node/https.ts`) and the agent reported `protocol: "http:"`, causing `http.ClientRequest` to throw `ERR_INVALID_PROTOCOL` against any `https:` URL. This broke `npm install` (via `make-fetch-happen` -> `@npmcli/agent` -> `agent-base`) and similar consumers. Encode the marker in the `request` function's name so its stack frame becomes `at node:https:request (...)`.
littledivy
pushed a commit
to crowlKats/deno
that referenced
this pull request
Jun 10, 2026
…and#34264) `npm install` (and any other consumer of `@npmcli/agent`, `http-proxy-agent`, or `https-proxy-agent`) has been failing under deno with `ERR_INVALID_PROTOCOL: Protocol "https:" not supported. Expected "http:"`, thrown synchronously from `http.ClientRequest`. The polymorphic agent in those packages, which extends `agent-base`, reports `protocol: "http:"` even for `https.request(...)`. The root cause is `agent-base@7`'s `protocol` getter. When its own setter hasn't run yet — the common case for the singleton agents `@npmcli/agent` caches — it falls back to scanning the current stack for `(https.js:` or `node:https:` to decide whether the caller is the https module. Real node satisfies that by virtue of its script URL (`node:https:NNN:CC`), but the deno polyfill's stack frames read `ext:deno_node/https.ts:NNN:CC`, so neither pattern matched, the agent assumed http, and `http.ClientRequest` saw `options.protocol "https:" !== agent.protocol "http:"` and threw. Encode the marker in the `request` function's name so its call frame reads `at node:https:request (...)` and agent-base's substring check matches. The added unit test mirrors agent-base's `protocol` getter exactly and asserts `https.request(httpsUrl, { agent })` no longer throws `ERR_INVALID_PROTOCOL`; with the marker removed the test fails with the original error, so it's a real regression guard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
npm install(and any other consumer of@npmcli/agent,http-proxy-agent, orhttps-proxy-agent) has been failing under denowith
ERR_INVALID_PROTOCOL: Protocol "https:" not supported. Expected "http:", thrown synchronously fromhttp.ClientRequest. Thepolymorphic agent in those packages, which extends
agent-base,reports
protocol: "http:"even forhttps.request(...).The root cause is
agent-base@7'sprotocolgetter. When its ownsetter hasn't run yet — the common case for the singleton agents
@npmcli/agentcaches — it falls back to scanning the current stackfor
(https.js:ornode:https:to decide whether the caller is thehttps module. Real node satisfies that by virtue of its script URL
(
node:https:NNN:CC), but the deno polyfill's stack frames readext:deno_node/https.ts:NNN:CC, so neither pattern matched, the agentassumed http, and
http.ClientRequestsawoptions.protocol "https:" !== agent.protocol "http:"and threw.Encode the marker in the
requestfunction's name so its call framereads
at node:https:request (...)and agent-base's substring checkmatches. The added unit test mirrors agent-base's
protocolgetterexactly and asserts
https.request(httpsUrl, { agent })no longerthrows
ERR_INVALID_PROTOCOL; with the marker removed the test failswith the original error, so it's a real regression guard.