Hono API on Vercel crashes with ERR_MODULE_NOT_FOUND when importing server files

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.json

The 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-spent

the request returns:

500: INTERNAL_SERVER_ERROR
Code: FUNCTION_INVOCATION_FAILED

Serverless Function Logs

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/server/app'
imported from /var/task/api/index.js

So it seems the serverless function cannot resolve:

../server/app

What 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 hono is listed in dependencies

Questions

  1. Does Vercel serverless only bundle files inside /api by default?
  2. Should the Hono app be moved into the /api directory?
  3. 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: GitHub - lancer751/hono-bun-react--demo · GitHub

If you’re having trouble deploying an Express app, this guide can help.

You can also ask v0 for suggestions tailored to your own project setup.

It looks like the issue is related to how Vercel bundles and deploys serverless functions, and it seems the app in the /server directory isn’t getting bundled correctly as part of the function in /api.

The module resolution system requires explicit file extensions in imports.

Could you try adding file extensions to the imports? Like:

import { something } from './server/file.js'