Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"TypeError: handler is not a function" error in Amplify deployed app but it works locally

I have an app built in Nexjs (13.4, Node 18.16) that calls a Lambda function (API Gateway).

I have the same versions locally, and it runs fine when I do npm run dev, but I hit an error when I try to launch the website through the Amplify link.

Cloudwatch shows this error:

TypeError: handler is not a function
at Server.<anonymous> (/tmp/app/server.js:29:11)
at Server.emit (node:events:513:28)
at parserOnIncoming (node:_http_server:998:12)
at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)

Any idea? Thanks

I'm new to this technology so it might be something simple but I don't find anything online.

The deployment was already problematic (AWS compatibility issues with Node 18.16), I use a public image as the initial container public.ecr.aws/docker/library/node:18.16.0

Anyway, I tried with an out of the box nextjs app (default app) and I hit the same issue, which is disturbing.

like image 803
100tifiko Avatar asked Sep 10 '25 03:09

100tifiko


2 Answers

I have the same problem with nextjs 13.4. I downgraded to 13.3 and it solved the problem and page renders fine. It seems like amplify is not fully ready for 13.4

like image 189
Mikkel Jensen Avatar answered Sep 14 '25 07:09

Mikkel Jensen


This is not an issue with AWS Amplify. The actual issue from nextjs 13.4.0 the server.js file created by the standalone output is incorrect because it does not wait until the Next handler is ready before node http server starts accepting requests. This has been fixed in next 13.4.2 version. Full details https://github.com/vercel/next.js/commit/0f332055d43fa97acbb52d7a9c187850bc08073f

like image 36
Devadyuti Das Avatar answered Sep 14 '25 08:09

Devadyuti Das