serverless-next.js: API routes return CloudFront 503 on `next` `12.0.9`
(I think this is a feature request, more than a bug 🤔)
Is your feature request related to a problem? Please describe.
When upgrading next from 12.0.8 to 12.0.9, API routes started to return a generic 503 from CloudFront.
- Update: I’m seeing the same error message that @jakubriedl posted ^1
TypeError: Cannot read property 'headers' of undefined
at Object.apiResolver (/var/task/chunks/89.js:10564:43)
at Module.<anonymous> (/var/task/chunks/89.js:6094:34)
A barebones API route (/api/health.ts) would return a generic 503 CloudFront error
import { NextApiHandler } from "next";
const handler: NextApiHandler = async (req, res) => {
return res.status(200).send("OK");
};
export default handler;
Describe the solution you’d like
For these to just work with next >= 12.0.9 🙏
"@sls-next/cdk-construct": "3.7.0-alpha.7",
"@sls-next/lambda-at-edge": "3.7.0-alpha.7",
Describe alternatives you’ve considered
Pin next to 12.0.8
Additional context
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 7
- Comments: 32 (5 by maintainers)
Hi everybody, I was having the 503 error today after setting up a pretty standard nextjs project using serverless-next.js 3.6.0, I thought it was a Lambda permission issue so I created a new role/policy but the error persisted, I’m using next 12.1.0 btw. Reading through the comments I saw some people mention the alpha pre-release so I tested 3.7.0-alpha.10 and boom, the default api that comes in the example project (api/hello) started working! I even removed the policy/role that I created and everything is still working just fine, I hope this helps someone too.
I apologize if this is not the right place to ask this question, but do you happen to know if AWS Amplify uses serverless-nextjs for deploying Next.js apps? When using Amplify to deploy our app I encounter the same issue (unless I switch to Next 12.0.8)
@jakubriedl thanks, I had gotten busy and had less time the past weeks so have just merged these changes. Will publish a new version soon.
Yup, I also had this issue.
Upgrading to
next@12.1.0and@3.7.0-alpha.11fixed everything for me. My/apiroutes no longer return 503.This issue has been resolved in v3.7.0-alpha.9. Thanks @dphang for publishing new version.
We are having same issue just with different error code. The error
Cannot read headers of undefinedis coming fromapiResolverfunction which is inside next. It seems there are changes withnext-serverless-loaderand this fileapi-utilswith works related to refactoring of BaseServer in12.0.9. Version 12.0.8 is working fine for us.the error as we see it in cloudwatch
Ok, so i tested this and looks like rewrites are broken also in
v3.7.0-alpha.8. I think I will debug a bit more and post a new issue.The problem with
useV2Handlerhas been resolved in v3.7.0-alpha.10.Got the same Issue and I switched to 12.0.8. Is there other suggestions to resolving the apiResolver?
Same error referenced above:
"TypeError: Cannot read property 'headers' of undefined", " at Object.apiResolver (/var/task/chunks/458.js:2435:43)", " at Module.<anonymous> (/var/task/chunks/458.js:49:34)@jakubriedl @Purii I just confirmed
12.0.8still works for me as well and updated the issue title 😃Same for us. It breaks from
12.0.8to12.0.9