Skip to content

v2.18.1 breaks React Native: DOMException is not globally available in Hermes #1871

@mfairley

Description

@mfairley

Description

livekit-client v2.18.1 crashes at module load time in React Native (Hermes engine) with:

ERROR  [ReferenceError: Property 'DOMException' doesn't exist]

Root Cause

PR #1820 ("Data track integration") added class DeferrableMapAbortError extends DOMException in src/utils/deferrable-map.ts. Since DOMException is not exposed as a global in React Native's Hermes engine, this extends clause fails at class evaluation time, preventing the entire SDK from loading.

There are also other DOMException references (e.g. new DOMException(...) in WebSocketStream.ts and abort-signal-polyfill.ts) that would fail at call time on affected code paths.

Environment

  • livekit-client: 2.18.1
  • @livekit/react-native: 2.10.0
  • React Native with Hermes engine (Expo)

Workaround

Adding a DOMException polyfill before any livekit imports:

if (typeof globalThis.DOMException === "undefined") {
  class DOMException extends Error {
    code: number;
    constructor(message?: string, name?: string) {
      super(message);
      this.name = name ?? "Error";
      this.code = 0;
    }
  }
  globalThis.DOMException = DOMException;
}

Suggested Fix

@livekit/react-native already polyfills WritableStream, ReadableStream, and crypto.randomUUID for React Native compatibility. A DOMException polyfill should be added there as well. Alternatively, the SDK could avoid extending DOMException directly to maintain compatibility with environments where it's not available.

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