Bug Description
When https_proxy or HTTP_PROXY environment variables are set, Gemini CLI crashes with:
TypeError: HttpsProxyAgent is not a constructor
at #prepareRequest (chunk-JS5WSGB2.js:14137:26)
Root Cause
gaxios (via @google/genai) dynamically imports https-proxy-agent:
this.#proxyAgent ||= (await import('https-proxy-agent')).HttpsProxyAgent;
This works correctly at runtime because Node.js's native CJS interop detects named exports from CJS modules. However, esbuild's code splitting (splitting: true) bundles https-proxy-agent (a CJS package) into a separate ESM chunk with only a default export:
// Generated chunk: dist-T73EYRDX.js
export default require_dist(); // { HttpsProxyAgent: [Function] }
When gaxios imports this chunk, .HttpsProxyAgent is undefined (it's on .default.HttpsProxyAgent), causing new undefined() → TypeError.
Reproduction
# Set any HTTP proxy
export https_proxy=http://127.0.0.1:7890
# Run gemini
gemini --prompt "hello" --yolo
# → TypeError: HttpsProxyAgent is not a constructor
Environment
- Gemini CLI: 0.37.1 (also affects 0.39.0-nightly based on source review)
- Node.js: v24.7.0
- OS: macOS (Darwin)
Fix
Mark https-proxy-agent as external in esbuild config and add it as a direct dependency, so Node.js's native CJS interop handles the import correctly. PR incoming.
Bug Description
When
https_proxyorHTTP_PROXYenvironment variables are set, Gemini CLI crashes with:Root Cause
gaxios(via@google/genai) dynamically importshttps-proxy-agent:This works correctly at runtime because Node.js's native CJS interop detects named exports from CJS modules. However, esbuild's code splitting (
splitting: true) bundleshttps-proxy-agent(a CJS package) into a separate ESM chunk with only adefaultexport:When gaxios imports this chunk,
.HttpsProxyAgentisundefined(it's on.default.HttpsProxyAgent), causingnew undefined()→ TypeError.Reproduction
Environment
Fix
Mark
https-proxy-agentas external in esbuild config and add it as a direct dependency, so Node.js's native CJS interop handles the import correctly. PR incoming.