Skip to content
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

Request body can't be read when running middleware in nodejs runtime #77551

Closed
kevva opened this issue Mar 27, 2025 · 0 comments · Fixed by #77553
Closed

Request body can't be read when running middleware in nodejs runtime #77551

kevva opened this issue Mar 27, 2025 · 0 comments · Fixed by #77553
Labels
Middleware Related to Next.js Middleware.

Comments

@kevva
Copy link
Contributor

kevva commented Mar 27, 2025

Link to the code that reproduces this issue

https://github.com/kevva/next-bugs/tree/node-middleware-bug

To Reproduce

  1. Start the application in development (next dev)
  2. Send a POST request with a body
curl --location 'http://localhost:3000/' \
  --header 'Content-Type: application/json' \
  --data '{"foo": "bar"}'

Current vs. Expected behavior

Current behaviour

When reading the body, the app will fail with the following error:

⨯ SyntaxError: "[object Object]" is not valid JSON
    at JSON.parse (<anonymous>)

Expected behaviour

The middleware should be able to read the body.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.4.0: Tue Mar  4 21:05:34 PST 2025; root:xnu-11417.100.576.505.3~2/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 23.10.0
  npm: 10.2.4
  Yarn: 1.22.21
  pnpm: 8.15.7
Relevant Packages:
  next: 15.3.0-canary.24 // Latest available version is detected (15.3.0-canary.24).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.8.2
Next.js Config:
  output: N/A

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

Middleware

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

next dev (local), next start (local)

Additional context

This works fine when running the middleware with the Edge runtime and only happens when running it in Node.js.

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

Successfully merging a pull request may close this issue.

1 participant