Invoke Error: Cannot Read Property '0' of Undefined
See original GitHub issueDescribe the bug
This is a bug that prevents the NextJS lambda from serving the site. It happens almost every other request and results in timeouts or cloudfront returning a 503.
Actual behavior
Causes timeouts or 503s from Cloudfront when the Lambda throws the exception. Happens every now and then, other times it will serve the site.
Expected behavior
Serve the site.
Steps to reproduce
Hard to say, all I do is visit the website through Chrome and it occurs. Seems to happen after a lot of inactivity (maybe a cold start problem?)
Screenshots/Code/Logs
Here’s an image of the frequency of the error: https://imgur.com/8TUkz2K
In the cloudwatch logs the lambda outputs the following Invoke Error:
{
"errorType": "TypeError",
"errorMessage": "Cannot read property '0' of undefined",
"stack": [
"TypeError: Cannot read property '0' of undefined",
" at isOriginResponse (/var/task/index.js:5623:25)",
" at Runtime.handler$1 [as handler] (/var/task/index.js:5390:9)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
]
}
And this leads to this line of code in the lambda:
const isOriginResponse = (event) => {
return event.Records[0].cf.config.eventType === "origin-response";
};
Which tracks back to this line in the src
: https://github.com/serverless-nextjs/serverless-next.js/blob/05fb0ebdf38096fb7e0427956c4747e782c680a8/packages/libs/lambda-at-edge/src/default-handler.ts#L568
I believe that the event.Records
property is undefined and this is causing the exception.
Versions
- OS/Environment: MacOS Catalina
- @sls-next/serverless-component version:
^1.17.0
- Next.js version:
9.5.5
Checklist
- [X ] You have reviewed the README and FAQs, which answers several common questions.
- [X ] Please first try using the latest
@sls-next/serverless-component
release version, which may have already fixed your issue. Note that the oldserverless-next.js
component and theserverless-next.js
plugin are deprecated and no longer maintained.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top GitHub Comments
that documentation is not giving enough idea that what was done I am facing the same issue , how do i resolve it ?
@jmrapp1 Can you explain in more details please how you solved this issue?