Skip to content

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

@TrevorBurnham

Description

@TrevorBurnham

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.

NEXT-4351

Metadata

Metadata

Assignees

No one assigned

    Labels

    linear: nextConfirmed issue that is tracked by the Next.js team.locked

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions