Summary
Calling new bdclient(...) throws synchronously under the Bun runtime with TypeError: dns is not a function. The SDK's Transport constructor calls interceptors.dns() from undici (dist/esm/core/transport.mjs:45), but Bun's bundled undici polyfill exposes only redirect, retry, and dump. Bun substitutes its own undici for the undici import regardless of what's installed in node_modules, so the userland undici@^7.16.0 dependency does not help. Underlying Bun gap: oven-sh/bun#19748.
Environment
@brightdata/sdk@1.1.0
- Bun
1.3.11
- macOS
arm64
- Also reproducible via
@mastra/brightdata@0.2.0, which calls new bdclient(...) inside its tool factories.
Repro
// repro.mjs
import { bdclient } from "@brightdata/sdk";
new bdclient({ apiKey: "any-string" });
console.log("OK — constructor returned");
$ bun run repro.mjs
TypeError: dns is not a function. (In 'dns()', 'dns' is undefined)
at new Transport (.../@brightdata/sdk/dist/esm/core/transport.mjs:45:20)
at new bdclient (.../@brightdata/sdk/dist/esm/client.mjs:82:26)
$ node repro.mjs
OK — constructor returned
Diagnostic
// undici-check.mjs
import * as u from "undici";
console.log("interceptors:", Object.keys(u.interceptors ?? {}));
# Bun
interceptors: [ 'redirect', 'retry', 'dump' ] // dns missing
# Node (real undici 7.16+)
interceptors: [ 'redirect', 'responseError', 'retry', 'dump', 'dns', 'cache', 'decompress', 'deduplicate' ]
Suggested fixes (any one would unblock callers on Bun)
- Guard the interceptor chain. In
Transport constructor, only compose dns() when interceptors.dns is a function. When it's absent (Bun), compose retry() alone. DNS resolution falls back to the platform default, which is acceptable for most callers.
- Drop the
interceptors.dns() dependency. Use Node's built-in dns module (or skip custom DNS handling entirely), removing the runtime requirement on undici's dns interceptor.
- Document Node-only support. Add a Bun-incompatibility note to the README and tighten the
engines field (currently node >=20.0.0 with no Bun caveat) so users discover the limitation before installing.
Summary
Calling
new bdclient(...)throws synchronously under the Bun runtime withTypeError: dns is not a function. The SDK'sTransportconstructor callsinterceptors.dns()fromundici(dist/esm/core/transport.mjs:45), but Bun's bundledundicipolyfill exposes onlyredirect,retry, anddump. Bun substitutes its ownundicifor theundiciimport regardless of what's installed innode_modules, so the userlandundici@^7.16.0dependency does not help. Underlying Bun gap: oven-sh/bun#19748.Environment
@brightdata/sdk@1.1.01.3.11arm64@mastra/brightdata@0.2.0, which callsnew bdclient(...)inside its tool factories.Repro
Diagnostic
Suggested fixes (any one would unblock callers on Bun)
Transportconstructor, only composedns()wheninterceptors.dnsis a function. When it's absent (Bun), composeretry()alone. DNS resolution falls back to the platform default, which is acceptable for most callers.interceptors.dns()dependency. Use Node's built-indnsmodule (or skip custom DNS handling entirely), removing the runtime requirement onundici'sdnsinterceptor.enginesfield (currentlynode >=20.0.0with no Bun caveat) so users discover the limitation before installing.