Skip to content

bdclient constructor throws under Bun runtime: 'dns is not a function' #24

Description

@jimmyhoran

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.mjsimport{bdclient}from"@brightdata/sdk";newbdclient({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.mjsimport*asufrom"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)

  1. 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.
  2. 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.
  3. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions