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

huangapple go评论74阅读模式
英文:

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

问题

我有一个使用 Nexjs(13.4,Node 18.16)构建的应用,调用一个 Lambda 函数(API Gateway)。

我在本地使用相同的版本运行npm run dev时,一切正常,但通过 Amplify 链接启动网站时出现错误。

Cloudwatch 显示以下错误:

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)

有什么想法?
谢谢

我对这项技术很新,所以可能是一些简单的问题,但我在网上找不到任何解决方法。

部署本身就有问题(与 Node 18.16 的 AWS 兼容性问题),我使用一个公共镜像作为初始容器public.ecr.aws/docker/library/node:18.16.0

无论如何,我尝试了一个开箱即用的 nextjs 应用(默认应用),但出现了相同的问题,这令人困扰。

英文:

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.

答案1

得分: 6

我遇到了与nextjs 13.4相同的问题。我降级到了13.3,问题得到了解决,页面呈现正常。似乎amplify还没有完全准备好13.4。

英文:

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

答案2

得分: 4

这不是AWS Amplify的问题。实际问题来自于nextjs 13.4.0版本中由独立输出创建的server.js文件不正确,因为它在Node HTTP服务器开始接受请求之前不等待Next处理程序准备就绪。这已在next 13.4.2版本中修复。完整详情请查看 https://github.com/vercel/next.js/commit/0f332055d43fa97acbb52d7a9c187850bc08073f

英文:

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

huangapple
  • 本文由 发表于 2023年5月10日 12:25:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76214881.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定