Skip to content

🐛 Issue: App Route fails with “No response is returned” only when running inside Docker container #140

@mr-kelly

Description

@mr-kelly

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 Response object 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 Response check.
  • 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

  1. Build and run the application inside a Docker container.
  2. Start the Next.js server.
  3. Call an App Route such as /api/health.
  4. Observe the runtime error: “No response is returned.”
  5. Run the same code outside Docker and observe that it works correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions