Updatedb script proxy compatibility#275
Conversation
# 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
|
Thanks for submitting. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
| : (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); | |
| } |
Fix: Support https-proxy-agent v7+ export format
Problem
The
updatedb.jsscript fails when usinghttps-proxy-agentv7+ with the error:This occurs because
https-proxy-agentchanged its export format:HttpsProxyAgentas 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
getHTTPOptionsfunction inscripts/updatedb.jsto handle both export formats:HttpsProxyAgent,default, or falls back to the module itselfThis maintains backward compatibility with v5/v6 while adding support for v7+.
Changes
scripts/updatedb.jsto handle both export formats ofhttps-proxy-agentTesting
Tested with:
https-proxy-agentv7.0.6http_proxy,https_proxy)The script now successfully:
https-proxy-agentRelated Issues
This fix addresses compatibility issues when:
https-proxy-agentv7.0.6 or laterBackward Compatibility
✅ Fully backward compatible with
https-proxy-agentv5 and v6 ✅ No breaking changes✅ No additional dependencies required