dotnet/aspnetcore · critical · Error

'EventSource' is not supported in your environment.

Error message

'EventSource' is not supported in your environment.

What it means

Thrown at HttpConnection.ts:535 inside _constructTransport when the ServerSentEvents transport is selected but `options.EventSource` is falsy. The constructor (lines 118-124) tries to populate it from the global EventSource in browsers or the `eventsource` npm module in Node; if neither is available the transport cannot operate.

Source

Thrown at src/SignalR/clients/ts/signalr/src/HttpConnection.ts:535

        }

        if (transportExceptions.length > 0) {
            return Promise.reject(new AggregateErrors(`Unable to connect to the server with any of the available transports. ${transportExceptions.join(" ")}`, transportExceptions));
        }
        return Promise.reject(new Error("None of the transports supported by the client are supported by the server."));
    }

    private _constructTransport(transport: HttpTransportType): ITransport {
        switch (transport) {
            case HttpTransportType.WebSockets:
                if (!this._options.WebSocket) {
                    throw new Error("'WebSocket' is not supported in your environment.");
                }
                return new WebSocketTransport(this._httpClient, this._accessTokenFactory, this._logger, this._options.logMessageContent!,
                    this._options.WebSocket, this._options.headers || {});
            case HttpTransportType.ServerSentEvents:
                if (!this._options.EventSource) {
                    throw new Error("'EventSource' is not supported in your environment.");
                }
                return new ServerSentEventsTransport(this._httpClient, this._httpClient._accessToken, this._logger, this._options);
            case HttpTransportType.LongPolling:
                return new LongPollingTransport(this._httpClient, this._logger, this._options);
            default:
                throw new Error(`Unknown transport: ${transport}.`);
        }
    }

    private _startTransport(url: string, transferFormat: TransferFormat): Promise<void> {
        this.transport!.onreceive = this.onreceive;
        if (this.features.reconnect) {
            this.transport!.onclose = async (e) => {
                let callStop = false;
                if (this.features.reconnect) {
                    try {
                        this.features.disconnected();
                        await this.transport!.connect(url, transferFormat);

View on GitHub (pinned to 294cab2f9b)

Solutions

  1. In Node, install `eventsource`: `npm install eventsource`.
  2. Provide a polyfill: `new HttpConnection(url, { EventSource: EventSourcePolyfill })`.
  3. Switch to a supported transport: `withUrl(url, { transport: HttpTransportType.LongPolling })` or let negotiation auto-select.
  4. In browsers, verify the global EventSource exists (modern evergreen browsers do).

Example fix

// before
new HubConnectionBuilder()
  .withUrl(url, { transport: HttpTransportType.ServerSentEvents })
  .build(); // throws in Node

// after
const EventSource = require('eventsource');
new HubConnectionBuilder()
  .withUrl(url, { transport: HttpTransportType.ServerSentEvents, EventSource })
  .build();
Defensive patterns

Strategy: validation

Validate before calling

function resolveEventSourceImpl() {
  if (typeof EventSource !== 'undefined') return EventSource;
  try { return require('eventsource'); } catch { return undefined; }
}
const ES = resolveEventSourceImpl();
if (!ES) throw new Error('EventSource unavailable - install eventsource or pick another transport');
const options = { transport: HttpTransportType.ServerSentEvents, EventSource: ES };

Type guard

function isEventSourceCtor(v: unknown): v is { new (url: string): any } {
  return typeof v === 'function';
}

Try / catch

try { await conn.start(transferFormat); }
catch (e) {
  if (/'EventSource' is not supported/.test(String(e))) {
    return new HttpConnection(url, { ...options, transport: HttpTransportType.LongPolling }).start(transferFormat);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running in Node without the `eventsource` package installed; an environment (older IE, some webviews) without a native EventSource; explicitly disabling it by setting `options.EventSource = null`; selecting the SSE transport explicitly when the environment doesn't support it.

Common situations: Node service that selected ServerSentEvents but lacks the `eventsource` dependency; bundler that stripped the dynamic require; targeting very old browsers; CI test runner without EventSource polyfill.

Related errors


AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06). Data as JSON: /api/errors/c132307cd853181e. Report an issue: GitHub.