{"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":"error","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/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/SignalR/clients/ts/signalr/src/HttpConnection.ts#L517-L553","documentation":"_constructTransport throws if ServerSentEvents was selected but options.EventSource is falsy. EventSource is resolved from the global EventSource (browser) or the 'eventsource' npm module under Node; if neither is present, SSE cannot be used.","triggerScenarios":"Transport selection picks HttpTransportType.ServerSentEvents but options.EventSource is undefined. The constructor only assigns EventSource when the global exists or, under Platform.isNode, require('eventsource') succeeded.","commonSituations":"Running in Node without the 'eventsource' package installed. Running in a non-browser environment without an EventSource polyfill. Bundler removed the dynamic require('eventsource'). User forced SSE transport in an environment that lacks it.","solutions":["Install 'eventsource' (npm install eventsource) when running on Node.","Provide an EventSource implementation explicitly: withUrl(url, { EventSource: MyESImpl }).","Switch to LongPolling or WebSockets, which may be available in your environment.","Confirm the bundler is not stripping the EventSource polyfill/global."],"exampleFix":"// before: Node without 'eventsource'\nconst conn = new signalR.HubConnectionBuilder()\n  .withUrl(url, { transport: signalR.HttpTransportType.ServerSentEvents })\n  .build();\n\n// after: supply an implementation\nimport EventSource from \"eventsource\";\nconst conn = new signalR.HubConnectionBuilder()\n  .withUrl(url, { transport: signalR.HttpTransportType.ServerSentEvents, EventSource })\n  .build();","handlingStrategy":"validation","validationCode":"function resolveEventSource(): typeof EventSource | undefined {\n  if (typeof EventSource !== \"undefined\") return EventSource;\n  try { return require(\"eventsource\"); } catch { return undefined; }\n}","typeGuard":"function hasEventSourceImpl(opts: signalR.IHttpConnectionOptions): boolean {\n  return typeof opts.EventSource === \"function\" || typeof EventSource !== \"undefined\";\n}","tryCatchPattern":"try { await connection.start(); }\ncatch (e) {\n  if (e instanceof Error && /'EventSource' is not supported/.test(e.message)) {\n    opts.EventSource = require(\"eventsource\");\n    return newConnection(opts);\n  }\n  throw e;\n}","preventionTips":["Install 'eventsource' on Node.","Pass EventSource explicitly in options for non-browser bundles.","If SSE is unavailable, switch the transport to LongPolling or WebSockets."],"tags":["transport","server-sent-events","environment","node","configuration"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}