Skip to content

[BUG] Hatchet Typescript SDK v1.22.2 cannot build with Bun #3926

@DeJayDev

Description

@DeJayDev

Describe the issue
Bundlers fail to build apps importing @hatchet-dev/typescript-sdk/v1 because v1/agent/openai.js contains a static require('@openai/agents') call that is statically traced by bundlers at build time. @openai/agents is not declared in the SDK's dependencies, peerDependencies, or optionalDependencies, so it is never installed, and the build fails with an unresolvable module error.

The runtime guard before the require (a try { require.resolve('@openai/agents') } catch {} check) protects Node at runtime, but does not help bundlers — they tokenize and resolve every literal require(...) call they can statically reach.

v1/agent/claude.js follows the same pattern with @anthropic-ai/claude-agent-sdk.

This was introduced between v1.22.0 and v1.22.1. v1.22.0 does not contain v1/agent/openai.js and builds cleanly. v1.22.1 and v1.22.2 both reproduce the failure.

Environment

  • SDK: @hatchet-dev/typescript-sdk v1.22.1, v1.22.2 (v1.22.0 unaffected)
  • Bundler: Bun bun build --target node (Bun versions v1.3.0 and v1.3.13 both reproduce). webpack/esbuild with static tracing will exhibit the same behavior.

Expected behavior
A library that ships optional integrations should let consumers build without installing every supported third-party SDK. Either:

  1. Declare @openai/agents and @anthropic-ai/claude-agent-sdk as optionalDependencies or peerDependenciesMeta.*.optional, OR
  2. Use a bundler-opaque dynamic import ((0, eval)('require')('@openai/agents'), new Function('return import(\"@openai/agents\")'), or await import('@openai/agents')) so static analysis does not try to resolve the module.

Code to Reproduce, Logs, or Screenshots

Reproducer (any consumer that imports HatchetClient from /v1):

// src/index.ts
import { HatchetClient } from '@hatchet-dev/typescript-sdk/v1'
console.log(HatchetClient.name)

Build:

$ bun build src/index.ts --target node --outdir dist
65 |     const { tool } = require('@openai/agents');
                                  ^
error: Could not resolve: "@openai/agents". Maybe you need to "bun install"?
    at node_modules/@hatchet-dev/typescript-sdk/v1/agent/openai.js:65:30

Offending lines in v1/agent/openai.js (1.22.1, 1.22.2):

// line 53 (inside OpenAIToolFunc)
try { require.resolve('@openai/agents'); } catch (_a) { hasOpenAIAgents = false; }
// ...
// line 65
const { tool } = require('@openai/agents');

v1/declaration.js makes agent/openai.js statically reachable from any /v1 import:

if (sdk === 'openai') {
    const { OpenAIToolFunc } = require('./agent/openai');
    return OpenAIToolFunc(this, ...args);
}
const { ClaudeToolFunc } = require('./agent/claude');
return ClaudeToolFunc(this, ...args);

Additional context
Workaround we are using until this is fixed: pinning the SDK to 1.22.0 via npm overrides. This avoids both the unresolvable require('@openai/agents') and the require('@anthropic-ai/claude-agent-sdk') site in agent/claude.js, and still picks up the protobufjs and OpenTelemetry transitive updates from the 1.22.x line.

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