Skip to content

Proxy broken: HttpsProxyAgent is not a constructor (esbuild CJS interop) #25169

Description

@yan5xu

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreIssues related to User Interface, OS Support, Core Functionalitystatus/need-triageIssues that need to be triaged by the triage automation.status/possible-duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions