{"record":{"id":"c132307cd853181e","repo":"dotnet/aspnetcore","slug":"eventsource-is-not-supported-in-your-environment","errorCode":null,"errorMessage":"'EventSource' is not supported in your environment.","messagePattern":"'EventSource' is not supported in your environment\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/SignalR/clients/ts/signalr/src/HttpConnection.ts","lineNumber":535,"sourceCode":"        }\n\n        if (transportExceptions.length > 0) {\n            return Promise.reject(new AggregateErrors(`Unable to connect to the server with any of the available transports. ${transportExceptions.join(\" \")}`, transportExceptions));\n        }\n        return Promise.reject(new Error(\"None of the transports supported by the client are supported by the server.\"));\n    }\n\n    private _constructTransport(transport: HttpTransportType): ITransport {\n        switch (transport) {\n            case HttpTransportType.WebSockets:\n                if (!this._options.WebSocket) {\n                    throw new Error(\"'WebSocket' is not supported in your environment.\");\n                }\n                return new WebSocketTransport(this._httpClient, this._accessTokenFactory, this._logger, this._options.logMessageContent!,\n                    this._options.WebSocket, this._options.headers || {});\n            case HttpTransportType.ServerSentEvents:\n                if (!this._options.EventSource) {\n                    throw new Error(\"'EventSource' is not supported in your environment.\");\n                }\n                return new ServerSentEventsTransport(this._httpClient, this._httpClient._accessToken, this._logger, this._options);\n            case HttpTransportType.LongPolling:\n                return new LongPollingTransport(this._httpClient, this._logger, this._options);\n            default:\n                throw new Error(`Unknown transport: ${transport}.`);\n        }\n    }\n\n    private _startTransport(url: string, transferFormat: TransferFormat): Promise<void> {\n        this.transport!.onreceive = this.onreceive;\n        if (this.features.reconnect) {\n            this.transport!.onclose = async (e) => {\n                let callStop = false;\n                if (this.features.reconnect) {\n                    try {\n                        this.features.disconnected();\n                        await this.transport!.connect(url, transferFormat);","sourceCodeStart":517,"sourceCodeEnd":553,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/SignalR/clients/ts/signalr/src/HttpConnection.ts#L517-L553","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["In Node, install `eventsource`: `npm install eventsource`.","Provide a polyfill: `new HttpConnection(url, { EventSource: EventSourcePolyfill })`.","Switch to a supported transport: `withUrl(url, { transport: HttpTransportType.LongPolling })` or let negotiation auto-select.","In browsers, verify the global EventSource exists (modern evergreen browsers do)."],"exampleFix":"// before\nnew HubConnectionBuilder()\n  .withUrl(url, { transport: HttpTransportType.ServerSentEvents })\n  .build(); // throws in Node\n\n// after\nconst EventSource = require('eventsource');\nnew HubConnectionBuilder()\n  .withUrl(url, { transport: HttpTransportType.ServerSentEvents, EventSource })\n  .build();","handlingStrategy":"validation","validationCode":"function resolveEventSourceImpl() {\n  if (typeof EventSource !== 'undefined') return EventSource;\n  try { return require('eventsource'); } catch { return undefined; }\n}\nconst ES = resolveEventSourceImpl();\nif (!ES) throw new Error('EventSource unavailable - install eventsource or pick another transport');\nconst options = { transport: HttpTransportType.ServerSentEvents, EventSource: ES };","typeGuard":"function isEventSourceCtor(v: unknown): v is { new (url: string): any } {\n  return typeof v === 'function';\n}","tryCatchPattern":"try { await conn.start(transferFormat); }\ncatch (e) {\n  if (/'EventSource' is not supported/.test(String(e))) {\n    return new HttpConnection(url, { ...options, transport: HttpTransportType.LongPolling }).start(transferFormat);\n  }\n  throw e;\n}","preventionTips":["In Node, install `eventsource` if you select SSE.","Pass an explicit EventSource polyfill in options.","Prefer LongPolling in Node if SSE isn't required."],"tags":["transport","server-sent-events","environment","node","polyfill"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}