Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I tried the basic example in the README. It failed with a 500 Internal Server Error and the following JSON body:
The output from the server process includes a stack trace. Sanitized a bit, it is:
Yet the docker-based demo app works. That uses Node.js v12.22.12. When I tried that Node version on the basic example, it also worked.
So, I used
nvm
to do a binary search on versions. I identified that Node.js v15.1.0 is the first failing version, and every version I tried that was newer (up to v21.2.0) also failed.Scouring the Node.js change log revealed that the http module of v15.1.0 started calculating req.headers lazily. There's a full discussion in nodejs/node#35281 [1]. Note the referenced issue that identifies the bug [2].
[1] nodejs/node#35281
[2] nodejs/node#36550
The workaround identified in this comment [3] is not to use the spread operator or
Object.assign
on the request object. "These objects are essentially uncloneable."[3] nodejs/node#36550 (comment)
This is surprisingly tricky to do right. Various Ramda functions like
merge
(and I thinkconverge
) do this implicitly, as does funky'sassocWith
. So to work around this limitation, while preserving all behavior, I had to resort to (gasp) mutating procedures instead of pure functions. Not ideal, I know. I'm open to better ideas.So, maybe this isn't the best solution, but it least it gets the example working again on modern Node versions. If it never gets merged, at least it will be findable via the repo on GitHub.
For reference, to test this, I used a fresh NPM project with only the paperplane dependency:
In which I added an index.js file with these contents:
And finally (with
fd
andentr
andhttpie
installed), I started a file-watching auto-test process: