Skip to content

Updatedb script proxy compatibility#275

Merged
bluesmoon merged 1 commit intogeoip-lite:mainfrom
tgabi333:patch-1
Nov 6, 2025
Merged

Updatedb script proxy compatibility#275
bluesmoon merged 1 commit intogeoip-lite:mainfrom
tgabi333:patch-1

Conversation

@tgabi333
Copy link
Copy Markdown
Contributor

@tgabi333 tgabi333 commented Nov 6, 2025

Fix: Support https-proxy-agent v7+ export format

Problem

The updatedb.js script fails when using https-proxy-agent v7+ with the error:

HttpsProxyAgent is not a constructor

This occurs because https-proxy-agent changed its export format:

  • v5/v6: Exports the constructor directly as the default export
  • v7+: Exports an object with HttpsProxyAgent as a named export: { HttpsProxyAgent: [class] }

This is particularly problematic when using package managers like pnpm that strictly enforce dependency resolution, as the script cannot access the constructor directly.

Solution

Updated the getHTTPOptions function in scripts/updatedb.js to handle both export formats:

  1. First checks if the required module is a function (v5/v6 format)
  2. Otherwise, tries to access HttpsProxyAgent, default, or falls back to the module itself

This maintains backward compatibility with v5/v6 while adding support for v7+.

Changes

  • Modified scripts/updatedb.js to handle both export formats of https-proxy-agent
  • Added comments explaining the compatibility logic

Testing

Tested with:

  • https-proxy-agent v7.0.6
  • pnpm package manager
  • Proxy environment variables set (http_proxy, https_proxy)

The script now successfully:

  • Downloads GeoIP databases from MaxMind
  • Works with proxy configurations
  • Maintains compatibility with older versions of https-proxy-agent

Related Issues

This fix addresses compatibility issues when:

  • Using pnpm or other strict package managers
  • Using https-proxy-agent v7.0.6 or later
  • Running the update script in environments with proxy configurations

Backward Compatibility

✅ Fully backward compatible with https-proxy-agent v5 and v6 ✅ No breaking changes
✅ No additional dependencies required

# Fix: Support https-proxy-agent v7+ export format

## Problem

The `updatedb.js` script fails when using `https-proxy-agent` v7+ with the error:
```
HttpsProxyAgent is not a constructor
```

This occurs because `https-proxy-agent` changed its export format:
- **v5/v6**: Exports the constructor directly as the default export
- **v7+**: Exports an object with `HttpsProxyAgent` as a named export: `{ HttpsProxyAgent: [class] }`

This is particularly problematic when using package managers like pnpm that strictly enforce dependency resolution, as the script cannot access the constructor directly.

## Solution

Updated the `getHTTPOptions` function in `scripts/updatedb.js` to handle both export formats:

1. First checks if the required module is a function (v5/v6 format)
2. Otherwise, tries to access `HttpsProxyAgent`, `default`, or falls back to the module itself

This maintains backward compatibility with v5/v6 while adding support for v7+.

## Changes

- Modified `scripts/updatedb.js` to handle both export formats of `https-proxy-agent`
- Added comments explaining the compatibility logic

## Testing

Tested with:
- `https-proxy-agent` v7.0.6
- pnpm package manager
- Proxy environment variables set (`http_proxy`, `https_proxy`)

The script now successfully:
- Downloads GeoIP databases from MaxMind
- Works with proxy configurations
- Maintains compatibility with older versions of `https-proxy-agent`

## Related Issues

This fix addresses compatibility issues when:
- Using pnpm or other strict package managers
- Using `https-proxy-agent` v7.0.6 or later
- Running the update script in environments with proxy configurations

## Backward Compatibility

✅ Fully backward compatible with `https-proxy-agent` v5 and v6
✅ No breaking changes
✅ No additional dependencies required
@bluesmoon
Copy link
Copy Markdown
Collaborator

Thanks for submitting.

@bluesmoon bluesmoon requested a review from Copilot November 6, 2025 18:51
@bluesmoon bluesmoon self-assigned this Nov 6, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes compatibility issues with https-proxy-agent v7+ in the updatedb.js script by handling the library's changed export format (from default export to named export).

  • Updates the proxy agent initialization to support both v5/v6 (default export) and v7+ (named export) formats
  • Adds defensive checks to gracefully handle different module export patterns
  • Maintains full backward compatibility with older versions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// Handle both v5/v6 (default export) and v7+ (named export) formats
var HttpsProxyAgent = typeof HttpsProxyAgentModule === 'function'
? HttpsProxyAgentModule
: (HttpsProxyAgentModule.HttpsProxyAgent || HttpsProxyAgentModule.default || HttpsProxyAgentModule);
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback logic || HttpsProxyAgentModule at the end of the ternary expression is redundant. If HttpsProxyAgentModule.HttpsProxyAgent and HttpsProxyAgentModule.default are both falsy, falling back to HttpsProxyAgentModule itself (which is not a function based on the initial check) will cause the same constructor error on line 153. Consider removing this fallback or adding error handling to provide a clearer error message when no valid constructor is found.

Suggested change
: (HttpsProxyAgentModule.HttpsProxyAgent || HttpsProxyAgentModule.default || HttpsProxyAgentModule);
: (HttpsProxyAgentModule.HttpsProxyAgent || HttpsProxyAgentModule.default);
if (typeof HttpsProxyAgent !== 'function') {
console.error("Could not find a valid HttpsProxyAgent constructor in https-proxy-agent module.");
process.exit(-1);
}

Copilot uses AI. Check for mistakes.
@bluesmoon bluesmoon merged commit 84ff81f into geoip-lite:main Nov 6, 2025
1 check failed
@tgabi333 tgabi333 deleted the patch-1 branch March 2, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants