Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploying to Vercel Serverless Functions #1256

Open
PodTT opened this issue Jul 22, 2023 · 10 comments
Open

Deploying to Vercel Serverless Functions #1256

PodTT opened this issue Jul 22, 2023 · 10 comments

Comments

@PodTT
Copy link

PodTT commented Jul 22, 2023

Is there any official way of deploying a hono app to Vercel serverless functions? I am not talking about edge. I am using prisma with Hono and it would be nice to deploy to serverless functions. As far as I know Prisma is not supported on edge runtimes, it seems like Vercel serverless functions are my only option. I could not find documentation on the website relating to this topic.

@yusukebe
Copy link
Member

Hi @PodTT

Have you tried it?

https://hono.dev/getting-started/vercel#node-js

@natemate90
Copy link

@yusukebe Trying this out as well. The app.get example provided is working. However, I get a server 500 error with any different method that I'm trying, i.e. app.post()

@sjc5
Copy link

sjc5 commented Sep 1, 2023

I'm seeing this as well when using c.req.formData() or c.req.parseBody() (which uses the formData method under the hood).

I suspect it may be related to this: https://github.com/orgs/vercel/discussions/1426

@sjc5
Copy link

sjc5 commented Sep 2, 2023

Update, it turns out you need to add NODEJS_HELPERS=0 to your environment variables, then Hono will work in Vercel serverless (AWS Lambda)

See https://vercel.com/docs/functions/serverless-functions/runtimes/node-js#disabling-helpers-for-node.js

@natemate90
Copy link

I'm still having trouble. I'll get a 500 response on any post method when adding a JSON payload (locally). It would be nice to see a complete working example somewhere

@engageintellect
Copy link

I couldn't get any of the examples in the docs working in vercel. Only locally. Guessing they haven't been updated.

@sandys
Copy link

sandys commented Sep 25, 2023

hi folks, we are interested in this as well. is this bug going to be fixed ?

also - we deploy using vercel deploy --prebuilt for all our code (which means we build to vercel build output locally). I'm migrating from hattip which builds and outputs Build Output compatible .vercel directories. Not sure if that is something Hono supports

@yusukebe
Copy link
Member

I would like to investigate but I am busy cleaning up other Issues, I think it may be a Vercel issue but I am not sure. I will investigate when I get some time.

@sjc5
Copy link

sjc5 commented Sep 27, 2023

I'm still having trouble. I'll get a 500 response on any post method when adding a JSON payload (locally). It would be nice to see a complete working example somewhere

This is an Hono server deployed to Vercel: https://github.com/hwy-js/hwy/tree/0f9d7f662984267e24e15a22c960425bcbdb92e2/docs

This does not use the Vercel CLI, so maybe that's where the issues are cropping up for others. Anyway, maybe this example can help someone. There aren't POSTs in this example, but works fine if you add them (both locally and when deployed).

The tricks are:

  1. Set NODEJS_HELPERS=0 in your Vercel production environment variables. POST requests break if you don't do this!
  2. Your function needs to be in an api folder, e.g., ~/api/main.js.
  3. Adjust vercel.json to point to your server entry file.

@sandys
Copy link

sandys commented Sep 28, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants