Help vercel • hono • serverless
Summary
I deployed a full-stack application using Hono for the API and Vite/React for the frontend. The deployment succeeds, but I can only the serverless function crashes in the preview page.
From the logs, it appears Vercel cannot resolve a module imported from outside the /api directory.
Project Setup
My project structure looks like this:
honno-react-demo│├ api│ └ index.ts│├ server│ ├ app.ts│ └ routes│ └ expenses.route.ts│├ frontend│ ├ src│ └ dist│└ package.jsonThe API entry file is:
/api/index.ts
import app from "../server/app";import { handle } from "hono/vercel";export const GET = handle(app);export const POST = handle(app);export const PUT = handle(app);export const PATCH = handle(app);export const DELETE = handle(app);export const OPTIONS = handle(app);My Hono app is defined in:
/server/app.ts
import { Hono } from "hono";import { logger } from "hono/logger";import { expensesRoute } from "./routes/expenses.route";const app = new Hono();app.use("*", logger());const apiRoutes = app .basePath("/api") .route("/expenses", expensesRoute);export default app;export type ApiRoutes = typeof apiRoutes;Current Behavior
The deployment completes successfully and the frontend loads, but when I call the API endpoint:
/api/expenses/total-spentthe request returns:
500: INTERNAL_SERVER_ERRORCode: FUNCTION_INVOCATION_FAILEDServerless Function Logs
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/server/app'imported from /var/task/api/index.jsSo it seems the serverless function cannot resolve:
../server/appWhat I’ve Tried
- Verified that the path is correct locally
- Confirmed the app works locally using
vercel dev - Removed any Bun-specific imports (
hono/bun) - Checked that
honois listed in dependencies
Questions
- Does Vercel serverless only bundle files inside
/apiby default? - Should the Hono app be moved into the
/apidirectory? - Is there a recommended structure for deploying a Hono API with Vercel?
Any guidance would be greatly appreciated. Thank you!
Here is the link to my repository: https://github.com/lancer751/hono-bun-react--demo