Module not found when deploying Hono Backend to Vercel

Hello friends at Vercel.

I have a monorepo with a Hono backend, which exports the Hono app instance from src/index.ts

Deployments of Hono work flawlessly until you start to add local modules outside of index.ts, such as src/lib/auth.ts, for example.

I have my Hono backend organized into sub-folders inside the src directory, containing business logic, authentication service and so on. The only solution I found to this issue for now is to dump them all into a monolithic src/index.ts, which is very far from convenient.

Other user in this forum happened to experience similar problem. Not sure if it may be down to the build tooling im using (tsdown), or the file extensions due to using Typescript but it’s been painful so far.

Hoping u guys can help me out! Happy to give access to the repository.

This is what my file tree looks like, for reference.

src/
β”‚   β”‚   β”‚   β”œβ”€β”€ index.ts          # Main hono entry point (had to consolidate everything here, lol)
β”‚   β”‚   β”‚   β”œβ”€β”€ db/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ index.ts      # Database connection
β”‚   β”‚   β”‚   β”‚   └── schema/       # Drizzle ORM schemas
β”‚   β”‚   β”‚   β”‚       β”œβ”€β”€ auth.ts   # User, session, account tables
β”‚   β”‚   β”‚   β”‚       └── todo.ts   # Todo table schema
β”‚   β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth.ts       # Better-auth configuration
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ context.ts    # Request context creation
β”‚   β”‚   β”‚   β”‚   └── orpc.ts       # ORPC server setup
β”‚   β”‚   β”‚   └── routers/
β”‚   β”‚   β”‚       β”œβ”€β”€ index.ts      # Main API router (health, private data)
β”‚   β”‚   β”‚       └── todo.ts 

Here are my logs:

2025-08-30T03:48:27.899Z [error] Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/apps/server/src/lib/auth' imported from /var/task/apps/server/src/lib/context.js
    at finalizeResolution (node:internal/modules/esm/resolve:281:11)
    at moduleResolve (node:internal/modules/esm/resolve:866:10)
    at moduleResolveWithNodePath (node:internal/modules/esm/resolve:990:14)
    at defaultResolve (node:internal/modules/esm/resolve:1033:79)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:780:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:704:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:687:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:305:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:137:49) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///var/task/apps/server/src/lib/auth'
}
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.
1 Like

Yeah, I’m experiencing the same thing on my repo with similar structure. Prod build works locally, even when I ship the index.js file out of my projects working dir.

The index.js file in dist\ after the build has the modules embedded correctly but the serverless function just crashes out, in my case with:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/apps/server/src/lib/context' imported from /var/task/apps/server/src/index.js

Can repro with a bare b-t-stack boilerplate:
pnpm create better-t-stack@latest connect-tanstack-hono --frontend tanstack-router --backend hono --runtime node --database postgres --orm prisma --api orpc --auth better-auth --payments none --addons husky oxlint turborepo --examples none --db-setup neon --web-deploy none --server-deploy none --git --package-manager pnpm --no-install

And deploy to vercel, the FE (in this case Vite) works as expected, the BE (Hono) builds okay but wont server requests

1 Like

In addition to this, when i test hono in isolation using the tsdown build in docker instance, it works as expected.
docker run -it --rm -v $(pwd):/app node:22-bullseye node /app/apps/server/dist/index.js

Hi @rokitg, I’m sorry you are facing this issue.

Have you referred to the Hono on Vercel and Vercel - Hono guides to see if there are some mismatch in default exports?

If possible, I’d recommend creating a vc init hono project and see if that works well. Then move your code from the old project gradually to this new project and see what breaks it.

I’m having the exact same issue. Even starting from the official example.

I think the problem comes from `vercel build` (the hono build script) - vercel/packages/hono/src/build.ts at main Β· vercel/vercel Β· GitHub

UPDATE:

I might have found a hacky workaround.

When importing internal TS modules likemyfile.ts, make sure you add a .js extension like import abc from "./myFile.js". This temporarily fixed my problem, but would still love to get a proper bug fix from Vercel SDK team.

4 Likes

@kevin-he in your case is it a mono repo (using turbo)?

My issue seems to come from using a mono repo with a src/server and packages/auth or packages/api, tsdown bundles the outputs into a single index.js file but for some reason vercel is still trying to look for the imports even when embedded by tsdown.

Seems like this might not be a hono issue, it might be with how vercel handles the workspace:* references in turbo. I was able to reproduce this error with Fastify also

Error [ERR_MODULE_NOT_FOUND]: Cannot find module β€˜/var/task/apps/server/node_modules/@test-btstest-bts/api/src/routers/index.ts’ imported from /var/task/apps/server/src/index.js

I am facing the same issue but with path alias. I raised an issue with Vercel here: Runtime error with TypeScript path aliases in Hono deployment: Cannot find package '@/constants' Β· Issue #14058 Β· vercel/vercel Β· GitHub

Someone found a workaround ? Because i have the same issue but on my Fastify api inside my turborepo.

Thankss