Skip to content

fix(csv-parse): only destroy on end when the stream has destroy (fix #409) - #538

Merged
wdavidw merged 1 commit into
adaltas:masterfrom
b84330808:fix/csv-parse-browser-destroy
Oct 22, 2026
Merged

wdavidw merged 1 commit into
adaltas:masterfrom
b84330808:fix/csv-parse-browser-destroy

Conversation

@b84330808

@b84330808 b84330808 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #409

The browser builds of csv-parse (csv-parse/browser/esm, iife, umd) bundle a stream polyfill whose Transform has no destroy method. When the parser stops early because of to or to_line, it calls this.destroy() once the stream has ended (and on an empty input it runs this.on("end", this.destroy)), which throws in the browser (this.destroy is not a function, or "listener" argument must be a function for the listener). Parsing itself still finishes, which is why the report says everything seems to work apart from the error.

This only calls or registers destroy when it is a function, which is the guard you suggested in #333 when the same thing came up in the browser. Node.js streams always have destroy, so nothing changes there.

The new tests in test/api.stream.destroy.ts remove destroy from a parser (with autoDestroy: false, otherwise Node calls it itself at finish) and cover to, to_line and empty input. They fail on master with the same error as the report. I also rebuilt the bundles locally and checked that dist/esm/index.js no longer throws with to and to_line. I left dist/ out of the PR since it's regenerated on release.

I used Claude Code to write this change.

@wdavidw

wdavidw commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

#513 is now merged, could you rebase your PR ?

…daltas#409)

The browser builds bundle a stream polyfill whose Transform has no
`destroy` method. When the parser stops because of the `to` or `to_line`
options, or ends on an empty input, it registers `this.destroy` as an
`end` listener, which throws "listener argument must be a function".

Register the listener only when `destroy` is a function. Node.js streams
always have it, so their behavior is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@b84330808
b84330808 force-pushed the fix/csv-parse-browser-destroy branch from 1ae3b76 to a33423b Compare October 22, 2026 02:00
@b84330808

Copy link
Copy Markdown
Contributor Author

Rebased! The to/to_line end handler from #513 now calls this.destroy() directly, so I put the same check inside its end() callback.

@wdavidw
wdavidw merged commit 9fabcbe into adaltas:master Oct 22, 2026
@wdavidw

wdavidw commented Oct 22, 2026

Copy link
Copy Markdown
Member

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error message when using vite

2 participants