diff --git a/rsbuild.config.ts b/rsbuild.config.ts index 336ab67d..794d9d63 100644 --- a/rsbuild.config.ts +++ b/rsbuild.config.ts @@ -14,6 +14,13 @@ export default defineConfig({ BROWSER_BUILD: true, }, }, + resolve: { + // proxy-agent is a Node.js-only package, exclude it from the browser bundle. + // The isNode() guard in http_client.ts ensures it's never called in browsers. + alias: { + 'proxy-agent': false, + }, + }, output: { distPath: { js: '.' }, filename: { js: 'bundle.js' }, diff --git a/src/http_client.ts b/src/http_client.ts index 773b4a64..77bc38b2 100644 --- a/src/http_client.ts +++ b/src/http_client.ts @@ -6,6 +6,7 @@ import type { RetryFunction } from 'async-retry'; import retry from 'async-retry'; import type { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'; import axios, { AxiosHeaders } from 'axios'; +import { ProxyAgent } from 'proxy-agent'; import { APIFY_ENV_VARS } from '@apify/consts'; import type { Log } from '@apify/log'; @@ -115,13 +116,8 @@ export class HttpClient { private async initNode(): Promise { if (!isNode()) return; - - const [{ ProxyAgent }, os] = await Promise.all([ - // eslint-disable-next-line @typescript-eslint/consistent-type-imports - dynamicNodeImport('proxy-agent'), - // eslint-disable-next-line @typescript-eslint/consistent-type-imports - dynamicNodeImport('node:os'), - ]); + // eslint-disable-next-line @typescript-eslint/consistent-type-imports + const os = await dynamicNodeImport('node:os'); // We want to keep sockets alive for better performance. // Enhanced agent configuration based on agentkeepalive best practices: