Skip to content

fix: use static import for proxy-agent to fix Bun single executable bundling#862

Open
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-dynamic-import-proxy-agent
Open

fix: use static import for proxy-agent to fix Bun single executable bundling#862
Copilot wants to merge 4 commits intomasterfrom
copilot/fix-dynamic-import-proxy-agent

Conversation

Copy link
Contributor

Copilot AI commented Mar 11, 2026

proxy-agent was wrapped in dynamicNodeImport() to hide it from browser bundlers, but this also prevents Bun (and similar tools) from statically discovering it when compiling single executables — causing a runtime Cannot find package 'proxy-agent' error.

Changes

  • src/http_client.ts: Replace dynamicNodeImport('proxy-agent') and dynamicNodeImport('node:os') with static top-level imports. proxy-agent is now statically discoverable by all bundlers targeting Node.js.
  • rsbuild.config.ts: Add resolve.alias: { 'proxy-agent': false } to exclude proxy-agent from the browser bundle (replaced with an empty stub). The existing isNode() guard in initNode() ensures ProxyAgent is never invoked in browsers.

The dynamicNodeImport helper is retained in utils.ts — it's still used for node:util/node:zlib in maybeGzipValue.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • accounts.google.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=4625 --enable-crash-reporter=, --noerrdialogs --user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-hxSEt6 --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,12594620577634490218,2558221868054857464,262144 --enable-features=PdfOopif --disable-features=AcceptCHFrame,IsolateSandboxedIframes,MediaRouter,OptimizationHints,PaintHolding,ProcessPerSiteUpToMainFrameThreshold,RenderDocument,Translate --variations-seed-version (dns block)
    • Triggering command: /home/REDACTED/.cache/puppeteer/chrome/linux-145.0.7632.77/chrome-linux64/chrome /home/REDACTED/.cache/puppeteer/chrome/linux-145.0.7632.77/chrome-linux64/chrome --allow-pre-commit-input --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-crash-reporter --disable-default-apps --disable-dev-shm-usage --disable-hang-monitor --disable-infobars --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --disable-search-engine-choice-screen --disable-sync --enable-automation (dns block)
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=4623 --enable-crash-reporter=, --noerrdialogs --user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-PtfD2g --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,4268284541091756514,2441462880767559678,262144 --enable-features=PdfOopif --disable-features=AcceptCHFrame,IsolateSandboxedIframes,MediaRouter,OptimizationHints,PaintHolding,ProcessPerSiteUpToMainFrameThreshold,RenderDocument,Translate --variations-seed-version (dns block)
  • android.clients.google.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=7110 --enable-crash-reporter=, --noerrdialogs --user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-U12B8K --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,2977454369542870675,10095175865921798865,262144 --enable-features=PdfOopif --disable-features=AcceptCHFrame,IsolateSandboxedIframes,MediaRouter,OptimizationHints,PaintHolding,ProcessPerSiteUpToMainFrameThreshold,RenderDocument,Translate --variations-seed-version (dns block)
    • Triggering command: /home/REDACTED/.cache/puppeteer/chrome/linux-145.0.7632.77/chrome-linux64/chrome /home/REDACTED/.cache/puppeteer/chrome/linux-145.0.7632.77/chrome-linux64/chrome --allow-pre-commit-input --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-crash-reporter --disable-default-apps --disable-dev-shm-usage --disable-hang-monitor --disable-infobars --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --disable-search-engine-choice-screen --disable-sync --enable-automation (dns block)
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=8124 --enable-crash-reporter=, --noerrdialogs --user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-P5FK71 --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,5837669430428856632,2929365918597363197,262144 --enable-features=PdfOopif --disable-features=AcceptCHFrame,IsolateSandboxedIframes,MediaRouter,OptimizationHints,PaintHolding,ProcessPerSiteUpToMainFrameThreshold,RenderDocument,Translate --variations-seed-version (dns block)
  • api.apify.com
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --conditions node --conditions development --experimental-import-meta-resolve --require /home/REDACTED/work/apify-client-js/apify-client-js/node_modules/vitest/suppress-warnings.cjs /home/REDACTED/work/apify-client-js/apify-client-js/node_modules/vitest/dist/workers/forks.js (dns block)
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=7110 --enable-crash-reporter=, --noerrdialogs --user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-U12B8K --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,2977454369542870675,10095175865921798865,262144 --enable-features=PdfOopif --disable-features=AcceptCHFrame,IsolateSandboxedIframes,MediaRouter,OptimizationHints,PaintHolding,ProcessPerSiteUpToMainFrameThreshold,RenderDocument,Translate --variations-seed-version (dns block)
    • Triggering command: /home/REDACTED/.cache/puppeteer/chrome/linux-145.0.7632.77/chrome-linux64/chrome /home/REDACTED/.cache/puppeteer/chrome/linux-145.0.7632.77/chrome-linux64/chrome --allow-pre-commit-input --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-crash-reporter --disable-default-apps --disable-dev-shm-usage --disable-hang-monitor --disable-infobars --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --disable-search-engine-choice-screen --disable-sync --enable-automation (dns block)
  • clients2.google.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=4624 --enable-crash-reporter=, --noerrdialogs --user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-kKvQpD --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,8286799380571886174,7468729252532740224,262144 --enable-features=PdfOopif --disable-features=AcceptCHFrame,IsolateSandboxedIframes,MediaRouter,OptimizationHints,PaintHolding,ProcessPerSiteUpToMainFrameThreshold,RenderDocument,Translate --variations-seed-version (dns block)
    • Triggering command: /home/REDACTED/.cache/puppeteer/chrome/linux-145.0.7632.77/chrome-linux64/chrome /home/REDACTED/.cache/puppeteer/chrome/linux-145.0.7632.77/chrome-linux64/chrome --allow-pre-commit-input --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-crash-reporter --disable-default-apps --disable-dev-shm-usage --disable-hang-monitor --disable-infobars --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --disable-search-engine-choice-screen --disable-sync --enable-automation (dns block)
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=4623 --enable-crash-reporter=, --noerrdialogs --user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-PtfD2g --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,4268284541091756514,2441462880767559678,262144 --enable-features=PdfOopif --disable-features=AcceptCHFrame,IsolateSandboxedIframes,MediaRouter,OptimizationHints,PaintHolding,ProcessPerSiteUpToMainFrameThreshold,RenderDocument,Translate --variations-seed-version (dns block)
  • www.google.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=4625 --enable-crash-reporter=, --noerrdialogs --user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-hxSEt6 --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,12594620577634490218,2558221868054857464,262144 --enable-features=PdfOopif --disable-features=AcceptCHFrame,IsolateSandboxedIframes,MediaRouter,OptimizationHints,PaintHolding,ProcessPerSiteUpToMainFrameThreshold,RenderDocument,Translate --variations-seed-version (dns block)
    • Triggering command: /home/REDACTED/.cache/puppeteer/chrome/linux-145.0.7632.77/chrome-linux64/chrome /home/REDACTED/.cache/puppeteer/chrome/linux-145.0.7632.77/chrome-linux64/chrome --allow-pre-commit-input --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-crash-reporter --disable-default-apps --disable-dev-shm-usage --disable-hang-monitor --disable-infobars --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --disable-search-engine-choice-screen --disable-sync --enable-automation (dns block)
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --mute-audio --crashpad-handler-pid=4623 --enable-crash-reporter=, --noerrdialogs --user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-PtfD2g --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,4268284541091756514,2441462880767559678,262144 --enable-features=PdfOopif --disable-features=AcceptCHFrame,IsolateSandboxedIframes,MediaRouter,OptimizationHints,PaintHolding,ProcessPerSiteUpToMainFrameThreshold,RenderDocument,Translate --variations-seed-version (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Dynamic import of proxy-agent breaks bun single executable bundling</issue_title>
<issue_description>Source code:

import { ApifyClient } from 'apify-client';

const client = new ApifyClient({
	token: process.env.APIFY_TOKEN,
});

const me = await client.user('me').get();

console.log(me);

Running like this works: APIFY_TOKEN="apify_api_you_wish" bun src/index.ts

Building into a single executable like so: bun build src/index.ts --target node --compile --outfile apifyclient followed by running it does not, and throws error: Cannot find package 'proxy-agent' from '/$bunfs/root/apifyclient'

In apify-cli I had to basically build bundles in 2 steps:

  1. single file executable that manually imports proxy-agent by adding in a import {} from "proxy-agent"
  2. patch the result to reference the manual import.

See the diff from the PR</issue_description>

<agent_instructions>Try implementing the fix ideated in the last comment. Make minimal changes to achieve the result. Add minimal comments, only if something is really hard to understand. use conventional commits for commit messages and PR title.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@barjin I believe this is essentially the same as #852 . The current setup doesn't expect the use of bundlers with Node environments.

Perhaps we can update the bundling setup (the one here, generating ./bundle.js), so it drops the isNode() blocks altogether, but keeps the imports discoverable when importing apify-client (not apify-client/browser).</comment_new>


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…undling

Co-authored-by: barjin <61918049+barjin@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix dynamic import of proxy-agent for bundling fix: use static import for proxy-agent to fix Bun single executable bundling Mar 11, 2026
@github-actions github-actions bot added this to the 136th sprint - Tooling team milestone Mar 11, 2026
@github-actions github-actions bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Mar 11, 2026
@barjin barjin marked this pull request as ready for review March 13, 2026 16:04
@barjin barjin linked an issue Mar 13, 2026 that may be closed by this pull request
@barjin barjin requested a review from vladfrangu March 13, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dynamic import of proxy-agent breaks bun single executable bundling Cannot find module 'proxy-agent' when using esbuild

2 participants