-
Notifications
You must be signed in to change notification settings - Fork 71
Description
Summary
After introducing an MCP route, Next.js App Routes fail at runtime with “No response is returned” only when the application is running inside a Docker container.
The same code works correctly in a non-Docker (local) environment.
The issue is caused by a newly added dependency that modifies global runtime state during startup.
Expected Behavior
- App Routes (e.g.
/api/health) should execute normally in all environments. - Returning a
Responseobject from a route handler should be correctly recognized by Next.js. - Behavior should be consistent between local execution and Docker container execution.
- Adding an MCP route should not affect unrelated App Routes.
Actual Behavior
- In a Docker container, when executing an App Route, Next.js fails its internal
instanceof Responsecheck. - The runtime throws the error:
No response is returned - The same route works correctly outside of Docker (in my localhost).
- The route handler does return a valid
Response, but Next.js fails to recognize it.
Root Cause (by Coding Agent)
The newly introduced MCP route brings in a dependency that patches global state at startup via undici/polyfill.
Inside the Docker runtime, this global patch causes a mismatch in the Response constructor used by Next.js, leading to a failed instanceof Response check during App Route execution.
This results in Next.js incorrectly reporting that no response was returned.
This is not an issue with the /api/health implementation itself, but an environment-sensitive side effect of global polyfilling.
Steps to Reproduce
- Build and run the application inside a Docker container.
- Start the Next.js server.
- Call an App Route such as
/api/health. - Observe the runtime error: “No response is returned.”
- Run the same code outside Docker and observe that it works correctly.