Fix Node.js 24 compatibility with Express/Next.js body parsers #2977
+0
−19
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.
Description
Fixes proxy method binding issue causing
request.urland other properties to be inaccessible in plugins when using Express with body parsers in Node.js 24.Related #2971
Changes
Fixed Request proxy handler: Added method wrapper to preserve
thiscontext when Request methods are accessed through proxy. Prevents "Illegal invocation" errors in Node.js 24.Refactored stream writing: Extracted
pumpToWritableutility function to consolidate duplicate async iterable and readable stream writing logic. Improves maintainability.Updated tests: Added reproduction test for Express + body parser + plugin scenario. Cleaned up console.log statements.
Technical Details
The proxy in
normalizeNodeRequestwasn't correctly binding methods when accessed. In Node.js 24's stricter environment with Express body parsers, this caused:Type of change
How Has This Been Tested?
express + body_parser + url property in the pluginTest Environment:
@whatwg-node/server: latestChecklist:
Further comments
The fix maintains backward compatibility while resolving method binding issues that surface under Node.js 24's stricter runtime checks, particularly when middleware like
express.json()modifies the request object before it reaches the adapter.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.