npm / eventsource-parser
eventsource-parser
What changed in eventsource-parser 2 to 4, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-30.
13 breaking4 new APIs and options3 performance1 behavior and defaults6 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initeventsource-parser 410 changes
Breaking changes 4
The CommonJS build and its
mainfield andrequireexport conditions are removed; Node 22.12 and above supportsrequire(esm)transparently.The package now requires Node.js >=22.12; Node.js 18 and 20 are no longer supported or guaranteed.
Invalid lines are discarded as soon as they cannot become a valid SSE field;
onErroris not called and noline,field, orvalueis retained.The root
stream.jsfile is removed; importeventsource-parser/streaminstead and ensure your bundler resolves theexportsfield.
New APIs and options 1
Adds a callback that reports ID fields when an event block ends, including blocks without data.
Performance 1
Avoids quadratic scanning of chunks containing many CR-terminated lines or a distant CR after LF-terminated lines.
Behavior and default changes 1
Partial comment lines are buffered only when an
onCommentcallback is configured; otherwise, they are discarded.
Fixes and other changes 3
Buffer limits are enforced while processing a chunk.
Handles leading byte-order marks across empty input chunks and split raw UTF-8 BOM chunks so the first event is not dropped.
A leading byte order mark is stripped whether it arrives as decoded
U+FEFFor as the raw three-byte sequence.
eventsource-parser 315 changes
Breaking changes 8
This type was removed in favor of the ParserCallbacks interface.
Replaces the ParsedEvent type; the type attribute has been removed.
The parser no longer takes an onParse callback; it takes an object of callbacks instead.
A new callback receives the reconnect interval directly.
This type was removed in favor of providing separate callbacks for each event type.
The parser now takes an object of callbacks instead of an onParse callback, allowing separate callbacks for each event type.
This type was removed; provide the interval directly to the onRetry callback.
Retry fields are parsed only when they contain completely valid integers.
New APIs and options 3
Adds the maxBufferSize option.
A new callback is available for handling comments.
A new callback is available for handling errors.
Performance 2
Avoids O(N²) behavior when a single SSE event spans many chunks.
Parsing is ~3.75x faster via inline fast-paths and single-pass line processing.
Fixes and other changes 2
An id: line containing a NULL character no longer wipes the buffered event id.
Mixed CRLF and LF line endings are now handled correctly.
eventsource-parser 22 changes
Breaking changes 1
The minimum supported Node.js version is now v18.
Fixes and other changes 1
Legacy exports are enabled, allowing developers to use them.