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.

Environment

  • Node.js 22.22.2
  • Current main

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