Skip to content
This repository has been archived by the owner on Jan 28, 2025. It is now read-only.

Fix the issue with TypeError hasHeader is not a function #329

Conversation

a14m
Copy link
Contributor

@a14m a14m commented Mar 25, 2020

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)

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)
@danielcondemarin
Copy link
Contributor

@a14m a14m force-pushed the bug/res.hasHeader-is-not-a-function branch from d321803 to 73f677c Compare March 26, 2020 08:51
@a14m a14m force-pushed the bug/res.hasHeader-is-not-a-function branch from 73f677c to 7a2de4a Compare March 26, 2020 09:22
Copy link
Contributor

@danielcondemarin danielcondemarin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@a14m
Copy link
Contributor Author

a14m commented Mar 26, 2020

also quick question, is there a reason why getHeader lower cases the header name, I think this can cause unintended behaviour... for example if

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

I'm working on an independent PR to fix the header cases separtely from this (#331 )

@danielcondemarin danielcondemarin merged commit 98f5598 into serverless-nextjs:master Mar 26, 2020
@a14m a14m deleted the bug/res.hasHeader-is-not-a-function branch March 26, 2020 09:33
@a14m
Copy link
Contributor Author

a14m commented Mar 26, 2020

Is it possible to give a time frame when this is supposed to be released (we depend on this to deploy to AWS and also to deploy to netlify through https://github.com/FinnWoelm/next-on-netlify/blob/master/package.json#L27)? and there is no safe stable way (I'm aware of) to link this specific package through yarn (without adding the monorepo package and relatively link the aws-lamda through the monorepo)

@joseocabarcas
Copy link

Thanks for fixing!
Is it possible to know when this fix could be published? I am depending on this to deploy aws. Please :)

@iamgbayer
Copy link

iamgbayer commented Mar 28, 2020

Thanks for fixing @a14m, I also would like to know when this could be published.

@danielcondemarin
Copy link
Contributor

Hi folks, sorry for the delay on publishing.
It has now been released next-aws-lambda@2.3.7, serverless-nextjs-plugin@2.4.8 🎉

@iamgbayer
Copy link

iamgbayer commented Mar 29, 2020

Hi @danielcondemarin,

I'm still receiving an error with hasHeader in a page that uses getServerSideProps, even updating the version, I'm using serverless-next.js on version 1.9.7

2020-03-29T20:11:19.446Z b6935fb7-e719-49f8-a684-d85e65904937 ERROR TypeError: res.hasHeader is not a function at sendPayload (/var/task/pages/index.js:15193:41) at renderReqToHTML (/var/task/pages/index.js:22480:13)

@a14m
Copy link
Contributor Author

a14m commented Mar 29, 2020

You need to update next-aws-lambda to at least ^2.3.7

@iamgbayer
Copy link

@a14m, why I need to update it? It isn't a dependency from serverless-next.js? Already has updated https://github.com/danielcondemarin/serverless-next.js/blob/master/packages/serverless-nextjs-component/package.json#L32

@a14m
Copy link
Contributor Author

a14m commented Mar 30, 2020

In theory that should fix the issue, but due to the complexity in package management (and JavaScript in general 😅) that’s not the case...
Can you verify that the version of next-aws-lambda is at least 2.3.7 In package-lock.json or yarn.lock

@iamgbayer
Copy link

In yarn.lock, I found next-aws-lambda with version 2.3.8, this should fix the problem, but I think it isn't happening in another part of the code.

@joseocabarcas
Copy link

@danielcondemarin I think this fix also needs to be added to next-aws-cloudfront.js of serverless-nextjs-component
I'm using serverless-next.js on version 1.9.7 but have same error

@zorzysty
Copy link

zorzysty commented Apr 3, 2020

I have "serverless-next.js": "^1.9.7" with "next-aws-lambda": "^2.3.8"
And the error still occurs.

a14m added a commit to infographicsgroup/serverless-next.js that referenced this pull request Apr 3, 2020
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
a14m added a commit to infographicsgroup/serverless-next.js that referenced this pull request Apr 3, 2020
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
@a14m
Copy link
Contributor Author

a14m commented Apr 3, 2020

I've added a fix for the issue (and the inconsistent header cases there too) in the 👆 PR

danielcondemarin pushed a commit that referenced this pull request Apr 4, 2020
…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
sclaughl pushed a commit to sclaughl/serverless-next.js that referenced this pull request Jul 16, 2020
…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
sclaughl pushed a commit to sclaughl/serverless-next.js that referenced this pull request Jul 16, 2020
…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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants