Nextjs and proxied requests error

Hi there,

We are experiencing an issue when we are using an HTTP proxy on Netlify. All proxied requests are failing with the following error:

{
“errorType”: “Runtime.UnhandledPromiseRejection”,
“errorMessage”: “Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client”,
“trace”: [
“Runtime.UnhandledPromiseRejection: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client”,
" at process. (/var/runtime/index.js:35:15)",
" at process.emit (events.js:314:20)",
" at processPromiseRejections (internal/process/promises.js:209:33)",
" at processTicksAndRejections (internal/process/task_queues.js:98:32)"
]
}

This issue appears only on Netlify, if you run the project locally or on Vercel there is no issue.

You can find the source code of a reproducible case on: GitHub - matthieuh/nextjs-netlify-issue

The application is deployed on

Any idea of the root cause of this issue?