Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
10 changes: 3 additions & 7 deletions src/http_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -115,13 +116,8 @@ export class HttpClient {

private async initNode(): Promise<void> {
if (!isNode()) return;

const [{ ProxyAgent }, os] = await Promise.all([
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
dynamicNodeImport<typeof import('proxy-agent')>('proxy-agent'),
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
dynamicNodeImport<typeof import('node:os')>('node:os'),
]);
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
const os = await dynamicNodeImport<typeof import('node:os')>('node:os');

// We want to keep sockets alive for better performance.
// Enhanced agent configuration based on agentkeepalive best practices:
Expand Down