NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
npm, #1309 most downloaded on npm
WhatWG/W3C compliant EventSource client for Node.js and browsers
Latest stable
5.1.5
Last release 14 days ago
08 Nov 2026
Ships unpredictably
gaps range from 9 days to 9 months
Nearly every release is documented
notes for 52 of 53 stable releases
Nothing withdrawn
no release was ever pulled
15 years old
55 releases · first in 2012
Drag across the ruler to compare, or tap a release to open it.
### Patch Changes - #376 `0ce156b` Thanks @renovate! - Update eventsource-parser to ^4.1.3.
### Patch Changes - #372 `0769591` Thanks @edsonsims! - Copy URL objects during construction so later caller mutations do not change the exposed URL o
0769591 Thanks @edsonsims! - Copy URL objects during construction so later caller mutations do not change the exposed URL or reconnection target.Your coding agent can read these notes before it upgrades. Set up the MCP server →
The event ID was passed to fetch() as a plain string header value, but header values are byte strings. An ID containing a character above U+00FF, eg €
#369 d3fe0d3 Thanks @rexxars! - Accept case variations of text/event-stream and reject different MIME subtypes such as text/event-streaming.
#370 02634eb Thanks @rexxars! - Avoid double-encoding non-ASCII event IDs when reconnecting with Cloudflare Workers' native fetch.
#367 fd62d79 Thanks @OsamaAnsar! - Fixed Last-Event-ID not being sent as UTF-8 on reconnect
The event ID was passed to fetch() as a plain string header value, but header values are byte strings. An ID containing a character above U+00FF, eg €, made fetch() throw a TypeError on every reconnect attempt, so the connection was never re-established. An ID with characters in the U+0080 to U+00FF range, eg é, was sent as a single Latin-1 byte instead of its UTF-8 encoding. The header now carries the UTF-8 bytes of the ID, as the specification requires.
### Patch Changes - #363 `c4d6b9a` Thanks @brennanbutler01! - Abort the underlying request when a response fails EventSource validation. - #362 `627eb
#363 c4d6b9a Thanks @brennanbutler01! - Abort the underlying request when a response fails EventSource validation.
#362 627eb17 Thanks @brennanbutler01! - Stop dispatching buffered messages when an event listener closes the connection.
The lastEventId attribute is the last event ID string of the event source, so an explicit id field persists until another one replaces it. Message eve
#358 de3c0ae Thanks @pacocartones! - Fixed MessageEvent.lastEventId being empty when a message omits the id field
The lastEventId attribute is the last event ID string of the event source, so an explicit id field persists until another one replaces it. Message events were dispatched with the current event's own id instead of that buffer, which left lastEventId empty on every event that omitted id, even though the buffer still held the earlier value and would have been sent as Last-Event-ID on reconnect.
17a9772 Thanks @rexxars! - Fixed ID-only event blocks not updating MessageEvent.lastEventId or Last-Event-ID on reconnect.
ReaderLike typed chunks read off the response body as unknown, but they are handed to a TextDecoder, which only accepts buffers and throws on anything
#355 d8370e4 Thanks @rexxars! - Typed response body chunks as buffers instead of unknown
ReaderLike typed chunks read off the response body as unknown, but they are handed to a TextDecoder, which only accepts buffers and throws on anything else. So a reader yielding anything else was never usable, and the type said otherwise. It also hid a type error in the client itself, which only surfaces when compiling against TypeScript's dom library: the node typings resolve the chunk to any, while the dom library resolves it to {}.
Chunks are now typed as Uint8Array | DataView | ArrayBuffer, which is what both the node and DOM typings accept, and which every fetch() implementation yields. Nothing changes at runtime.
If you pass a custom fetch() that returns a hand-rolled body, and your reader's chunk type is wider than the above, eg unknown or any, it will no longer be assignable. Returning a real Response, or a reader that yields Uint8Array chunks, is unaffected.
#355 008f07e Thanks @rexxars! - Declared the this type for the onerror, onmessage and onopen properties
addEventListener() already declared that listeners are called with the EventSource instance as this, but the on* properties did not, so this was an implicit any in handlers assigned to them (an error under noImplicitThis). They now match addEventListener() and the native EventSource:
eventSource.onmessage = function (event) {
console.log(this.url, event.data) // `this` is now typed
}
Handlers that declare an incompatible this, eg an unbound class method typed with this: MyClass, will now be rejected where they were previously accepted. Arrow functions and handlers that ignore this are unaffected.
#355 3512add Thanks @rexxars! - Made the exported EventSource type structural, so other implementations can satisfy it
EventSource was exported as a class holding hard-private (#) fields, which makes TypeScript emit a #private brand into the declaration file and turns the exported type nominal. A consumer writing function connect(es: EventSource) against this package could not pass the native EventSource, a mock, or any other implementation, even when the shape matched exactly.
The implementation class is now internal, and EventSource is exported as an interface plus a const holding the constructor. As a result:
EventSource, along with mocks and stubs, is assignable to the exported EventSource typeglobalThis.EventSource are interchangeable in both directions, which helps libraries that accept an EventSource implementation to constructEventSourceConstructor type is exported for that caseNothing changes at runtime: new EventSource(...), instanceof, subclassing, the readyState statics, EventSource.name, inspected output and the eventsource.supports-fetch-override symbol all behave as before, and the internal state is still held in real #private fields.
#357 8e5c691 Thanks @rexxars! - Fixed origin and lastEventId being empty on Cloudflare Workers
workerd accepts data from the MessageEvent constructor's init dictionary but silently drops origin and lastEventId, so message events dispatched on Cloudflare Workers arrived with origin set to null and lastEventId to an empty string. Both are now assigned explicitly when the constructor did not take them, which leaves every other runtime untouched.
BREAKING CHANGE: Node.js 22.12 or later is now required. Older Node.js versions may still work, but are not supported or guaranteed going forward beca…
b195e70 Thanks @rexxars! - - BREAKING CHANGE: The client now fails the connection, emitting an error without reconnecting, if the parser buffers 100 MB without receiving a valid, complete EventSource line. Configure a different limit with maxBufferSize; ideally, servers should emit smaller chunks or newlines more frequently.
require() of ESM, so most CommonJS consumers should continue to work. This removes the dual-package hazard.on* property handler and an addEventListener() listener are registered for the same event, they now run in registration order instead of always running the on* handler first. Code that relied on the old order can observe a different callback sequence.### Patch Changes - #351 `6127f40` Thanks @rexxars! - Allow a value of any type in ReaderLike done-results. TypeScript 5.9's DOM lib types ReadableStr
6127f40 Thanks @rexxars! - Allow a value of any type in ReaderLike done-results. TypeScript 5.9's DOM lib types ReadableStreamDefaultReader.read()'s done-result as {done: true, value: T | undefined}, so a custom fetch returning a Response-shaped body no longer satisfied FetchLikeResponse on TypeScript 5.9 and newer, forcing consumers to hand-wrap the reader.declare fetch override support symbol on class
FetchLikeInit is now removed. Use EventSourceFetchInit.
FetchLikeInit is now removed. Use
EventSourceFetchInit.FetchLikeInit type. Use EventSourceFetchInit instead. (6786e46)This release is also available on:
mark fetch init properties required in typings
upgrade parser to latest version, improving performance
include message and code on errors when logging in node.js and deno
Nothing published for this version
ensure message is set on ErrorEvent on network errors
This release is also available on:
reference possibly missing event typings
This release is also available on:
Drop support for Node.js versions below v18
headers in init dict dropped, pass a custom fetch function instead.fetch function instead.https.* options dropped. Pass a custom fetch function that provides an agent/dispatcher instead.dispatchEvent now emits entire event object (eb430c0)This release is also available on:
Nothing published for this version
strip sensitive headers on redirect to different origin
Fix URL is not a constructor error for browser (#268 Ajinkya Rajput)
URL is not a constructor error for browser (#268 Ajinkya Rajput)Removed dependency on url-parser. Fixes CVE-2022-0512 & CVE-2022-0691 (#249 Alex Hladin)
Inline origin resolution, drops original dependency (#281 Espen Hovlandsdal)
original dependency (#281 Espen Hovlandsdal)Do not include authorization and cookie headers on redirect to different origin (#273 Espen Hovlandsdal)
Improve performance for large messages across many chunks (#130 Trent Willis)
Add dispatchEvent to EventSource (#101 Ali Afroozeh)
Fix issue where a unicode sequence split in two chunks would lead to invalid messages (#108 Espen Hovlandsdal)
Check for window existing before polyfilling. (#80 Neftaly Hernandez)
window existing before polyfilling. (#80 Neftaly Hernandez)Pass withCredentials on to the XHR. (#79 Ken Mayer)
Nothing published for this version
Fix proxy not working when proxy and target URL uses different protocols. (#76 Espen Hovlandsdal)
Reconnect if server responds with HTTP 500, 502, 503 or 504. (#74 Vykintas Narmontas)
Add missing removeEventListener-method. (#51 Yucheng Tu / Espen Hovlandsdal)
removeEventListener-method. (#51 Yucheng Tu / Espen Hovlandsdal)Fix onConnectionClosed firing multiple times resulting in multiple connections. (#61 Phil Strong / Duncan Wong)
Don't include test files in npm package. (#56 eanplatter)
Add http/https proxy function. (#46 Eric Lu)
Renamed repository to eventsource (since it's not just Node, but also browser polyfill). (Aslak Hellesøy).
eventsource (since it's not just Node, but also browser polyfill). (Aslak Hellesøy).Ignore headers without a value. (#41, #43 Adriano Raiano)
Refactor tests to support Node.js 0.12.0 and Io.js 1.1.0. (Aslak Hellesøy)
Expose status property on error events. (#40 Adriano Raiano)
Made message properties enumerable. (#37 Golo Roden)
Blank lines not read. (#35, #36 Lesterpig)
Fix message type. (#33 Romain Gauthier)
High CPU usage by replacing Jison with port of WebKit's parser. (#25, #32, #18 qqueue)
Provide Event argument on open and error event (#30, #31 Donghwan Kim)
Old "last-event-id" used on reconnect (#27 Aslak Hellesøy)
Allow unauthorized HTTPS connections by setting rejectUnauthorized to false. (Aslak Hellesøy)
rejectUnauthorized to false. (Aslak Hellesøy)Explicitly raise an error when server returns http 403 and don't continue (#20 Scott Moak)
Add Accept: text/event-stream header (#17 William Wicks)
Add no-cache and https support (#10 Einar Otto Stangvik)
Automatic reconnect every second if the server is down. Reconnect interval can be set with reconnectInterval (not in W3C spec). (Aslak Hellesøy)
reconnectInterval (not in W3C spec). (Aslak Hellesøy)Jison based eventstream parser (#2 Einar Otto Stangvik)
Use native EventListener (Aslak Hellesøy)
### Features - First release (Aslak Hellesøy)
One column per quarter.