Skip to content

postinstall: binary download fails silently behind HTTP proxy (Node.js https ignores https_proxy) #201

@Astro-Han

Description

@Astro-Han

Environment

  • OS: macOS 26.3.1 (Darwin 25.3.0) arm64
  • lark-cli version: v1.0.2 (also reproduced on v1.0.0)
  • Node.js: v25.8.2
  • npm: 11.11.1
  • Installation method: npm global install
  • Network: Behind HTTP proxy (https_proxy=http://127.0.0.1:7897)

Description

npm install -g @larksuite/cli completes without error, but the bin/ directory is empty — the Go binary is never downloaded. The postinstall script (scripts/install.js) uses Node.js native https.get() which does not honor the https_proxy / HTTP_PROXY environment variables. In mainland China (and other regions where GitHub is slow or blocked), this causes the download to fail silently.

curl and wget in the same shell session work fine because they respect proxy environment variables.

Steps to Reproduce

  1. Set an HTTP proxy:

    export https_proxy=http://127.0.0.1:7897
  2. Install lark-cli:

    npm install -g @larksuite/cli
  3. Check the binary:

    ls $(npm root -g)/@larksuite/cli/bin/
    # Empty directory — no binary
  4. Verify curl works with the same proxy:

    curl -fSL -o /tmp/lark-cli.tar.gz \
      "https://github.com/larksuite/cli/releases/download/v1.0.2/lark-cli-1.0.2-darwin-arm64.tar.gz"
    # Downloads successfully at ~5 MB/s

Expected Behavior

The postinstall script should download the binary successfully when a proxy is configured via standard environment variables.

Suggested Fix

Replace https.get() with curl in scripts/install.js. curl is available on macOS, Linux, and Windows 10+ (built-in), and automatically respects proxy environment variables.

// Current: Node.js https (ignores proxy)
function download(url, destPath) {
  return new Promise((resolve, reject) => {
    const client = url.startsWith("https") ? https : require("http");
    client.get(url, (res) => { ... });
  });
}

// Suggested: curl (respects proxy)
function download(url, destPath) {
  return new Promise((resolve, reject) => {
    try {
      execSync(`curl -fSL --max-time 60 -o "${destPath}" "${url}"`, {
        stdio: "inherit",
      });
      resolve();
    } catch (e) {
      reject(new Error(`curl download failed: ${url}`));
    }
  });
}

Alternatively, use a proxy-aware HTTP library like node-fetch with https-proxy-agent, or pass the proxy to https.get() via the agent option.

Workaround

After installation, manually run:

curl -fSL -o /tmp/lark-cli.tar.gz \
  "https://github.com/larksuite/cli/releases/download/v1.0.2/lark-cli-1.0.2-darwin-arm64.tar.gz"
tar -xzf /tmp/lark-cli.tar.gz -C /tmp/
cp /tmp/lark-cli $(npm root -g)/@larksuite/cli/bin/lark-cli
chmod 755 $(npm root -g)/@larksuite/cli/bin/lark-cli

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions