Skip to content

[BUG] TypeError: e is not a constructor when HTTP_PROXY/HTTPS_PROXY env vars are set (regression in v2.33.0) #1204

Closed

Description

@bux

Since v2.33.0, the CLI crashes at startup with TypeError: e is not a constructor whenever HTTP_PROXY, http_proxy, HTTPS_PROXY, or https_proxy environment variables are set. This is a regression introduced by PR #1196 ("update proxy-agent to newer version"), which bumped proxy-agent from 6.5.0 → 8.0.1. v2.32.0 is unaffected.

Steps to Reproduce

  1. Set HTTP_PROXY or HTTPS_PROXY (or their lowercase variants) in your environment
  2. Run any openapi-generator-cli command:
HTTP_PROXY=http://proxy.example.com:3128 openapi-generator-cli generate \
  -i openapi.yaml -g typescript-angular -o ./generated
  1. See error

Expected behavior

The CLI should start normally and proceed with code generation, as it did in v2.32.0.

Error shown

TypeError: e is not a constructor
    at Array.<anonymous> (/…/node_modules/@openapitools/openapi-generator-cli/main.js:2:374)
    at o (/…/node_modules/@openapitools/openapi-generator-cli/main.js:2:53914)
    ...
Node.js v20.20.2
Error: Process completed with exit code 1.

Operation System

  • OS: Linux (self-hosted GitHub Actions runner), also reproducible on macOS
  • Version: Ubuntu 22.04 / macOS

Package System

npm

Additional context

The bug is in apps/generator-cli/src/app/app.module.ts (introduced in commit 15a4632, PR #1196):

const ProxyAgent = require('proxy-agent').default ?? require('proxy-agent');
httpModuleConfig.httpAgent = new ProxyAgent(); // ← crashes

proxy-agent@6.5.0 exported the class directly, so require('proxy-agent') was the constructor. proxy-agent@8.0.1 changed to named exports ... require('proxy-agent') now returns { ProxyAgent, ... } with no .default property, so the ?? fallback returns the module object, and new on a plain object throws.

Activity

  1. added
    bugSomething isn't working
    on May 19, 2026
  2. wing328 commented on May 19, 2026

    @wing328
    Member

    thanks for reporting the bug.

    just filed #1206 to revert the change

    but got errors (https://github.com/OpenAPITools/openapi-generator-cli/actions/runs/26088889697/job/76709055286?pr=1206), which is why we made the mentioned change.

     PASS   generator-cli  apps/generator-cli/src/app/services/pass-through.service.spec.ts (5.943 s)
     FAIL   generator-cli  apps/generator-cli/src/app/app.module.spec.ts
      ● Test suite failed to run
        apps/generator-cli/src/app/app.module.ts:4:28 - error TS2307: Cannot find module 'proxy-agent' or its corresponding type declarations.
        4 import { ProxyAgent } from 'proxy-agent';
                                     ~~~~~~~~~~~~~
     PASS   generator-cli  apps/generator-cli/src/app/services/config.service.spec.ts
     PASS   generator-cli  apps/generator-cli/src/app/controllers/version-manager.controller.spec.ts
    

    do you have any clue how to fix it? would appreciate your suggestions on how to fix the issue

  3. wing328 commented on May 19, 2026

    @wing328
    Member

    for those impacted by this, please pin the version to v2.32.0 for the time being.

  4. wing328 commented on May 19, 2026

    @wing328
    Member

    @bux for v2.32.0, if a wrong proxy is specified, will it be ignored (no error thrown)?

    I tried to added a test (https://github.com/OpenAPITools/openapi-generator-cli/pull/1206/changes#diff-5c3fa597431eda03ac3339ae6bf7f05e1a50d6fc7333679ec38e21b337cb6721R96) but it won't fail so wondering if that's the correct behaviour.

  5. bux commented on May 19, 2026

    @bux
    Author

    @wing328

    Just out of the top of my head it should be:

    - const ProxyAgent = require('proxy-agent').default ?? require('proxy-agent');
    + const { ProxyAgent } = require('proxy-agent');

    shouldn't it? 😄

    for v2.32.0, if a wrong proxy is specified, will it be ignored (no error thrown)?

    in v2.32.0 proxy-agent@6.5.0 exports the constructor directly, so new ProxyAgent() succeeds and the agent is created

  6. wing328 commented on May 19, 2026

    @wing328
    Member

    yes, that's what i did before but the job failed (couldn't find proxy-agent even thought it's defined in package.json, yarn.lock) and that's why i took the suggestion from co-pilot but it turns out it won't work during runtime.

    please have a look at the latest change in https://github.com/OpenAPITools/openapi-generator-cli/pull/1206/changes

  7. wing328 commented on May 20, 2026

    @wing328
    Member

    merged the fix (after some more tests) and released https://github.com/OpenAPITools/openapi-generator-cli/releases/tag/v2.34.0

    can you please give it a try ?

  8. bux commented on May 21, 2026

    @bux
    Author

    @wing328 Successfully tested locally. Thank you!

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions