You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
req.query is now a getter and can't use as custom server in front of Next.js #6633
When using Express as a custom server in front of Next.js, accessing req.query directly no longer returns a mutable plain object. Instead, it is now a getter, and attempts to modify it or use it as a plain object lead to unexpected behavior or errors.
This change affects routes where the server modifies or depends on the mutability of req.query before passing it to Next.js, breaking compatibility with existing implementations.
We applied the following patch, but we do not believe it is the best solution:
// Express 5 makes the 'query' property read-only, but Next.js needs to write to ittry{Object.defineProperty(req,'query',descriptor);}catch(error){// If property already exists and is configurable, delete and recreate ittry{// eslint-disable-next-line @typescript-eslint/no-explicit-anydelete(reqasany).query;Object.defineProperty(req,'query',descriptor);logger.logInfo(`query property fixed ${error}`,requestID);}catch(error){logger.logWarn(`Could not fix query property for Next.js compatibility: ${error}`,requestID);}}
Is it possible to know why Express decided to change? This would help us understand where we need to make adjustments (on the Next.js side or the Express.js side).
While I wasn't around at the time when that commit was made and possibly discussed, I found reasons (#3472 (comment), #2752 (comment)) from the former maintainer for making this just a getter.
The long-term solution is to use req.locals to store the query and modify it later, i'm not sure how this could work for Next.js, #3472 (comment)
Activity
bjohansebas commentedon Jul 13, 2025
While I wasn't around at the time when that commit was made and possibly discussed, I found reasons (#3472 (comment), #2752 (comment)) from the former maintainer for making this just a getter.
The long-term solution is to use req.locals to store the query and modify it later, i'm not sure how this could work for Next.js, #3472 (comment)