-
Notifications
You must be signed in to change notification settings - Fork 27.9k
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
Serverless: switching from getInitialProps to getServerSideProps causes "res.hasHeader is not a function" error #11223
Comments
When deploying to netlify or AWS (both depend on AWS-lambda) The SSR components (using `getServerSideProps` fails with the following error: ``` ERROR TypeError: res.hasHeader is not a function at sendPayload (/var/task/pages/test.js:5787:41) at renderReqToHTML (/var/task/pages/test.js:1773:13) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Module.render (/var/task/pages/test.js:1816:22) ``` This is caused by nextjs trying to use the default node `hasHeader` method here: https://github.com/zeit/next.js/blob/v9.3.1/packages/next/next-server/server/send-payload.ts#L25 This commit fix the issue reported here: vercel/next.js#11223 which I could verify also happening on our stack by adding the method that mimics the nodeJS method (using `res.getHeader(name)` internally wrapping it in boolean response)
@zorzysty I had the same issue and digging deep I found the culprit to be |
Thanks @a14m. This indeed looks like an issue with serverless-next.js and not next.js itself. |
* Fix the issue with TypeError hasHeader is not a function When deploying to netlify or AWS (both depend on AWS-lambda) The SSR components (using `getServerSideProps` fails with the following error: ``` ERROR TypeError: res.hasHeader is not a function at sendPayload (/var/task/pages/test.js:5787:41) at renderReqToHTML (/var/task/pages/test.js:1773:13) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Module.render (/var/task/pages/test.js:1816:22) ``` This is caused by nextjs trying to use the default node `hasHeader` method here: https://github.com/zeit/next.js/blob/v9.3.1/packages/next/next-server/server/send-payload.ts#L25 This commit fix the issue reported here: vercel/next.js#11223 which I could verify also happening on our stack by adding the method that mimics the nodeJS method (using `res.getHeader(name)` internally wrapping it in boolean response) * Add testing for `hasHeader` method
When deploying to netlify or AWS (both depend on AWS-lambda) The SSR components (using `getServerSideProps` fails with the following error: ``` ERROR TypeError: res.hasHeader is not a function at sendPayload (/var/task/pages/test.js:5787:41) at renderReqToHTML (/var/task/pages/test.js:1773:13) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Module.render (/var/task/pages/test.js:1816:22) ``` This is caused by nextjs trying to use the default node `hasHeader` method here: https://github.com/zeit/next.js/blob/v9.3.1/packages/next/next-server/server/send-payload.ts#L25 This commit fix the issue reported here: vercel/next.js#11223 which I could verify also happening on our stack by adding the method that mimics the nodeJS method (using `res.getHeader(name)` internally wrapping it in boolean response) Previously fixed for next-aws-lambda in serverless-nextjs#329
When deploying to netlify or AWS (both depend on AWS-lambda) The SSR components (using `getServerSideProps` fails with the following error: ``` ERROR TypeError: res.hasHeader is not a function at sendPayload (/var/task/pages/test.js:5787:41) at renderReqToHTML (/var/task/pages/test.js:1773:13) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Module.render (/var/task/pages/test.js:1816:22) ``` This is caused by nextjs trying to use the default node `hasHeader` method here: https://github.com/zeit/next.js/blob/v9.3.1/packages/next/next-server/server/send-payload.ts#L25 This commit fix the issue reported here: vercel/next.js#11223 which I could verify also happening on our stack by adding the method that mimics the nodeJS method (using `res.getHeader(name)` internally wrapping it in boolean response) Previously fixed for next-aws-lambda in serverless-nextjs#329
…t a function (#342) * Fix the issue with TypeError hasHeader is not a function When deploying to netlify or AWS (both depend on AWS-lambda) The SSR components (using `getServerSideProps` fails with the following error: ``` ERROR TypeError: res.hasHeader is not a function at sendPayload (/var/task/pages/test.js:5787:41) at renderReqToHTML (/var/task/pages/test.js:1773:13) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Module.render (/var/task/pages/test.js:1816:22) ``` This is caused by nextjs trying to use the default node `hasHeader` method here: https://github.com/zeit/next.js/blob/v9.3.1/packages/next/next-server/server/send-payload.ts#L25 This commit fix the issue reported here: vercel/next.js#11223 which I could verify also happening on our stack by adding the method that mimics the nodeJS method (using `res.getHeader(name)` internally wrapping it in boolean response) Previously fixed for next-aws-lambda in #329 * Fix the headers to always work with lower case Previously the following behaviour could be observed: ``` res.setHeader("X-CUSTOM", "VAL") res.getHeader("X-CUSTOM") => null res.hasHeader("X-CUSTOM") => false res.setHeader("x-custom", "val") res.getHeader("X-CUSTOM") => "val" res.hasHeader("X-CUSTOM") => true ``` There is no way of accessing a header that isn't set in lower case, This fixes the issue by always storing the header name as lower case, allowing a similar behaviour to node HTTP ResponseObject behaviour - https://nodejs.org/api/http.html#http_request_getheader_name - https://nodejs.org/api/http.html#http_request_removeheader_name - https://nodejs.org/api/http.html#http_request_setheader_name_value Previously fixed for next-aws-lambda in #331 * Update the npm package-lock
…nextjs#329) * Fix the issue with TypeError hasHeader is not a function When deploying to netlify or AWS (both depend on AWS-lambda) The SSR components (using `getServerSideProps` fails with the following error: ``` ERROR TypeError: res.hasHeader is not a function at sendPayload (/var/task/pages/test.js:5787:41) at renderReqToHTML (/var/task/pages/test.js:1773:13) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Module.render (/var/task/pages/test.js:1816:22) ``` This is caused by nextjs trying to use the default node `hasHeader` method here: https://github.com/zeit/next.js/blob/v9.3.1/packages/next/next-server/server/send-payload.ts#L25 This commit fix the issue reported here: vercel/next.js#11223 which I could verify also happening on our stack by adding the method that mimics the nodeJS method (using `res.getHeader(name)` internally wrapping it in boolean response) * Add testing for `hasHeader` method
…t a function (serverless-nextjs#342) * Fix the issue with TypeError hasHeader is not a function When deploying to netlify or AWS (both depend on AWS-lambda) The SSR components (using `getServerSideProps` fails with the following error: ``` ERROR TypeError: res.hasHeader is not a function at sendPayload (/var/task/pages/test.js:5787:41) at renderReqToHTML (/var/task/pages/test.js:1773:13) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Module.render (/var/task/pages/test.js:1816:22) ``` This is caused by nextjs trying to use the default node `hasHeader` method here: https://github.com/zeit/next.js/blob/v9.3.1/packages/next/next-server/server/send-payload.ts#L25 This commit fix the issue reported here: vercel/next.js#11223 which I could verify also happening on our stack by adding the method that mimics the nodeJS method (using `res.getHeader(name)` internally wrapping it in boolean response) Previously fixed for next-aws-lambda in serverless-nextjs#329 * Fix the headers to always work with lower case Previously the following behaviour could be observed: ``` res.setHeader("X-CUSTOM", "VAL") res.getHeader("X-CUSTOM") => null res.hasHeader("X-CUSTOM") => false res.setHeader("x-custom", "val") res.getHeader("X-CUSTOM") => "val" res.hasHeader("X-CUSTOM") => true ``` There is no way of accessing a header that isn't set in lower case, This fixes the issue by always storing the header name as lower case, allowing a similar behaviour to node HTTP ResponseObject behaviour - https://nodejs.org/api/http.html#http_request_getheader_name - https://nodejs.org/api/http.html#http_request_removeheader_name - https://nodejs.org/api/http.html#http_request_setheader_name_value Previously fixed for next-aws-lambda in serverless-nextjs#331 * Update the npm package-lock
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
Component using SSR works flawlessly on localhost both using
getInitialProps
andgetServerSideProps
.It also works on serverless when using
getInitialProps
, but causes a 500 error on serverless when usinggetServerSideProps
.Here are the error logs:
Here's the code for
getInitialProps
:Here's the code for
getServerSideProps
:Screenshots
Here's what's actually being rendered

System information
The text was updated successfully, but these errors were encountered: