bun
bun copied to clipboard
`body-parser` errors out when Content-Type is present in express.js
What version of Bun is running?
0.3.0
What platform is your computer?
Darwin 22.1.0 arm64 arm
What steps can reproduce the bug?
Repro script:
curl https://gist.githubusercontent.com/noway/87e2fba1fc4dd3d026a482126f770d92/raw/ade797bef21e81e7a94796a21dd23e9bc506734a/bun-express-body-parser-bug.sh | bash
Alternatively, go to https://gist.github.com/noway/87e2fba1fc4dd3d026a482126f770d92 and copy-paste the script into Terminal.
What is the expected behavior?
No errors, "ok" printed to console.
What do you see instead?
Two errors:
TypeError: Can only call StringDecoder.write on instances of StringDecoder
at /Users/ilia/compiling/bun-express-body-parser-bug/node_modules/iconv-lite/lib/bom-handling.js:35:14
at onData (/Users/ilia/compiling/bun-express-body-parser-bug/node_modules/raw-body/index.js:259:16)
at addChunk (node:stream:3015:8)
at readableAddChunk (node:stream:2988:12)
at node:http:191:8
at node:stream:3234:8
273 | received: received,
274 | type: 'request.size.invalid'
275 | }))
276 | } else {
277 | var string = decoder
278 | ? buffer + (decoder.end() || '')
^
TypeError: Can only call StringDecoder.end on instances of StringDecoder
at onEnd (/Users/ilia/compiling/bun-express-body-parser-bug/node_modules/raw-body/index.js:278:20)
at endReadableNT (node:stream:3706:8)
Additional information
Seems to be only happening when Content-Type header is supplied. When I try removing Content-Type header on line index.ts:16, the bug goes away, but I can't do that for my use case since I am actually trying to send a request from a browser which sends it regardless.
Thank you for the report & repro
Just tested the repro script on bun v0.4.0:
TypeError: undefined is not an object (evaluating 'this.#bodyStream.on')
at node:http:198:23
POST - http://localhost:3000/ failed
Error: undefined is not an object (evaluating 'this.#bodyStream.on')
at errorOrDestroy (native)
at <anonymous> (node:stream:3194:11)
Looks like the error changed (progress yay) but the use case of using body-parser still doesn't work.