Repository navigation
does not work with Node's stream.pipeline() built-in #1
Copy link
Copy link
Closed as not planned
Labels
👀 no/externalThis makes more sense somewhere elseThis makes more sense somewhere else👎 phase/noPost cannot or will not be acted onPost cannot or will not be acted on
Description
Initial checklist
- I read the support docs
- I read the contributing guide
- I agree to follow the code of conduct
- I searched issues and couldn’t find anything (or linked relevant results below)
Affected packages and versions
unified-stream@9, unified-stream@10
Link to runnable example
No response
Steps to reproduce
{
"private": true,
"name": "unified-stream-bug",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"dependencies": {
"rehype-format": "^4.0.1",
"rehype-parse": "^8.0.4",
"rehype-stringify": "^9.0.3",
"unified": "^10.1.2",
"unified-stream": "^2.0.0"
}
}// index.js
import {pipeline} from 'node:stream'
import {stream} from 'unified-stream'
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
import rehypeFormat from 'rehype-format'
import rehypeStringify from 'rehype-stringify'
pipeline(
process.stdin,
stream(
unified()
.use(rehypeParse)
.use(rehypeFormat)
.use(rehypeStringify)
),
process.stdout,
(err) => {
if (!err) return;
console.error(err)
process.exit(1)
},
)echo -e 'foo\nbar' | node index.js
<html>
<head></head>
<body>
foo
bar
</body>
</html>
file:///Users/j/playground/unified-stream-bug/node_modules/unified-stream/index.js:49
throw new Error('Did not expect `write` after `end`')
^
Error: Did not expect `write` after `end`
at write (file:///Users/j/playground/unified-stream-bug/node_modules/unified-stream/index.js:49:17)
at EventEmitter.end (file:///Users/j/playground/unified-stream-bug/node_modules/unified-stream/index.js:90:9)
at Socket.<anonymous> (node:internal/streams/pipeline:364:11)
at Object.onceWrapper (node:events:627:28)
at Socket.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1359:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Node.js v19.4.0
Expected behavior
As unified-stream (claims to?) returns a duplex Node stream, I would expect to be able to use it in combination with stream.pipeline().
Actual behavior
It fails with an error, see the reproduction steps.
Affected runtime and version
node@19.4.0
Affected package manager and version
No response
Affected OS and version
No response
Build and bundle tools
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
👀 no/externalThis makes more sense somewhere elseThis makes more sense somewhere else👎 phase/noPost cannot or will not be acted onPost cannot or will not be acted on
Activity
wooorm commentedon Apr 20, 2023
Trying that locally on Node 19.8.1, everything works fine.
Can you provide more info on OS/etc? Test more things?
wooorm commentedon Apr 20, 2023
I can produce the error on Node 19.3.0 🤔 Weird! Not sure what happened there. But this project has been working for ages!
And it works again on Node 19.5
wooorm commentedon Apr 20, 2023
It looks like this: nodejs/node#46205.
Apparently there was a bug with Node calling
endtwice in 17.3+. I also can repro it on 18.2. It seems fixed in 19.5. I also see that it was backported to at least 18.16 (maybe earlier)?I think it’s a clear bug in Node. Adding a workaround here for calling
endtwice to not throw, seems like it might silence more bugs.So: recommend you update your engines! :)
github-actions commentedon Apr 20, 2023