fix(npm): bypass @npmcli/agent to fix proxy env var crash#21832
Open
GoldJohnKing wants to merge 4 commits intoanomalyco:devfrom
Open
fix(npm): bypass @npmcli/agent to fix proxy env var crash#21832GoldJohnKing wants to merge 4 commits intoanomalyco:devfrom
GoldJohnKing wants to merge 4 commits intoanomalyco:devfrom
Conversation
When HTTP_PROXY/HTTPS_PROXY env vars are set, @npmcli/arborist's
dependency chain (@npmcli/agent) creates a proxy agent whose .proxy
getter returns { url: URL_object }. Bun's node:http polyfill reads
this and passes it to native fetch(), which expects proxy.url to be a
string, not a URL instance. This triggers:
fetch() proxy.url must be a non-empty string
Pass agent:false to Arborist to skip @npmcli/agent entirely. Bun's
native fetch layer then handles proxy via its own env var fallback
(HTTP_PROXY/HTTPS_PROXY), which works correctly with string URLs.
Fixes anomalyco#21098
Fixes anomalyco#21327
Fixes anomalyco#21468
Fixes anomalyco#21472
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
tricktron
reviewed
Apr 10, 2026
Co-authored-by: tricktron <tgagnaux@gmail.com>
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.
Issue for this PR
Closes #21098
Closes #21327
Closes #21468
Closes #21472
Type of change
What does this PR do?
When
HTTP_PROXY/HTTPS_PROXYenv vars are set, plugin installation via npm crashes withfetch() proxy.url must be a non-empty string.The cause is a type mismatch between
@npmcli/agentand Bun'snode:httppolyfill. Arborist's dependency chain uses@npmcli/agentwhich reads proxy env vars and exposes.proxyas{ url: URL_object }(a JSURLinstance, not a string). Bun'snode:httppolyfill (_http_client.ts) readsagent.proxyand passes it to nativefetch(). Bun's native fetch validates thatproxy.urlis a string, but aURLobject fails this check.The fix: pass
agent: falsetoArboriston Bun runtime. This skips@npmcli/agententirely. Bun'sFetchTaskletthen handles proxy itself by readingHTTP_PROXY/HTTPS_PROXYfromprocess.envas plain strings, which works correctly. The option is only applied whentypeof Bun !== "undefined", so Node.js is unaffected.How did you verify your code works?
tsc --noEmit— no new errors insrc/npm/index.tsbun run script/build.ts --single --skip-embed-web-ui --skip-install— smoke test (--version) passedfetch.zig,FetchTasklet.zig,_http_client.ts) and@npmcli/agentsource to confirm the fix routes proxy through Bun's working env var fallback pathScreenshots / recordings
N/A — no UI change.
Checklist