Skip to content

Error when using Express 5 as custom server: "Cannot set property query of #<IncomingMessage> which has only a getter" #79158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
TrevorBurnham opened this issue May 13, 2025 · 4 comments

Comments

@TrevorBurnham
Copy link

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/ws2m7y

To Reproduce

  1. Start the custom server in development mode with node server.mjs
  2. Navigate to /api/hello in the browser

The response will fail and the console will show this error:

 ⨯ [TypeError: Cannot set property query of #<IncomingMessage> which has only a getter] {
  page: '/api/hello'
}

Current vs. Expected behavior

I had no trouble using Express 4 as a custom server in front of Next.js. But when I tried to upgrade to Express 5, I started seeing this error when trying to access any API endpoint in the Pages Router. Pages still load fine.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4242
  Available CPU cores: 2
Binaries:
  Node: 20.12.0
  npm: 10.5.0
  Yarn: 1.22.19
  pnpm: 8.15.6
Relevant Packages:
  next: 15.2.0 // There is a newer version (15.3.2) available, upgrade recommended! 
  eslint-config-next: 15.2.0
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

I was able to reproduce the same error in 14.2.26. My guess would be that Next.js has always had a compatibility issue with Express 5, though if that's the case then I'm surprised I haven't seen more reports of this issue.

@rachel-bernard
Copy link

rachel-bernard commented May 19, 2025

I have exactly this issue. I was also surprised why I haven't seen it reported anywhere.
I thought once I was able to upgrade to next v15 it might resolve but it has not.

My API routes are not getting hit and I see the error TypeError: Cannot set property query of #<IncomingMessage> which has only a getter
I am not attempting to set the value of query or req.query anywhere.

Everything else is working fine in my application, the only issue I have is when I try to call an API route.

@arishoham
Copy link

Getting the same issue, looks to be caused by this line

@AlfonsZunderSystems
Copy link

"next": "^15.1.7",

The same problem . No "req.query =". when i use fetch post to get data to push in a datatable--> TypeError: Cannot set property query of # which has only a getter

My error is in compiling time.

my code

export default async function handler(req, res) {
console.log('hello!');
}

S.O.S

any idea?

i use custom-server.

@marceljager9
Copy link

marceljager9 commented May 22, 2025

same issue here

I get error 500 when calling api route

export default function handler(
  req: NextApiRequest,
  res: NextApiResponse<ResponseData>
) {
  res.status(200).json({ message: 'Hello from Next.js!' })
}

next: 15.3.2
express: 5.1.0

custom server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants