Use in bundled environments
This page applies only to non-Node.js environments (browsers, Cloudflare Workers, edge runtimes). If you're running on Node.js, you can skip it.
Browser bundle
The package ships a pre-built browser bundle at dist/bundle.js. A bundler that targets the browser picks it up through the browser condition of the package's exports field. If yours doesn't, import it directly:
import { ApifyClient } from 'apify-client/browser';
The bundle is self-contained and needs no polyfill configuration.
Bundling the ES module build yourself
The client's own code runs on Web APIs. The parts that need Node.js built-ins, such as request body compression and Node.js streams, live in a single module that the #runtime entry of the package's imports field selects at bundle time. The node condition gets the Node.js implementation, every other target gets the Web API one. A bundler targeting a browser, Cloudflare Workers, or another edge runtime therefore gets no node:zlib, node:os, or node:stream import from the client itself.
The client's dependencies still import a few Node.js built-ins: node:events, node:crypto and node:stream. In Cloudflare Workers, turn on the nodejs_compat compatibility flag to provide them.
Reaching the ES module build takes a bundler that doesn't set the browser condition, which resolves apify-client to the pre-built bundle. esbuild's neutral platform sets no conditions, and webpack and Vite let you list them through resolve.conditionNames and resolve.conditions.
Features that need Node.js
These features rely on Node.js APIs and aren't available in the browser bundle or in the Web API runtime:
- Log redirection with
RunClient.getStreamedLog(). - Request body compression.
- The
User-Agentheader, which browsers don't let a page set.
Streamed responses and raw bytes use Web APIs, so they work the same way in every runtime: LogClient.stream() and the stream option of DatasetClient.downloadItems() and KeyValueStoreClient.getRecord() return a web ReadableStream, and raw bytes are a Uint8Array.