Skip to content

WebSocket clients ignore Node's global WebSocket in ESM builds #4764

Description

@georgeglarson

Description

The package is emitted as ESM, and Node 22 provides a standards-compatible globalThis.WebSocket. The conversation and bash event clients only check window.WebSocket, then attempt require('ws'). Since require is unavailable in ESM, starting either client reports that no WebSocket implementation is available.

Steps to reproduce

  1. Install dependencies and build the package on Node 22.
  2. Import WebSocketCallbackClient from dist/events/websocket-client.js in an ESM process.
  3. Create a client and call start().
node --input-type=module -e "const {WebSocketCallbackClient}=await import('./dist/events/websocket-client.js'); const client=new WebSocketCallbackClient({host:'http://127.0.0.1:9',conversationId:'test',callback:()=>{},onError:console.error}); client.start(); client.stop()"

Expected behavior

The client uses Node's global WebSocket constructor.

Actual behavior

The error callback receives WebSocket implementation not available, even though globalThis.WebSocket exists. This is reproducible after the repository setup command uv sync --dev and the TypeScript package build complete.

Acceptance Criteria

  • The TypeScript WebSocket callback clients use globalThis.WebSocket in Node ESM when available.
  • The fallback path still supports injected WebSocket implementations and browser window.WebSocket.
  • A TypeScript client test covers Node's global WebSocket constructor path.

Environment

  • Node.js 22.22.2
  • Current main

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