Skip to content

Vercel deployment fails for Hono server in Turborepo monorepo #898

Closed

Description

@KingJune28

Description

When deploying a Hono server generated by create-better-t-stack (with Turborepo + Prisma + Better-Auth + tRPC) to Vercel, the deployment fails with multiple issues that require significant manual workarounds.

Stack Configuration

  • Frontend: Next.js
  • Backend: Hono
  • Monorepo: Turborepo
  • Database: Prisma with Neon (serverless PostgreSQL)
  • Auth: Better-Auth
  • API: tRPC

Issues Encountered

1. @t3-oss/env-core TypeScript inference error on Vercel

The Vercel build fails with type errors in packages/env/src/server.ts:

Type 'ZodString' is not assignable to type '`DATABASE_URL should not prefixed with ${string}.`'

Root cause: createEnv({ server: {...} }) without clientPrefix causes TypeScript to infer TPrefix as string instead of undefined, triggering the ServerOptions error branch for every env var.

Workaround: Add clientPrefix: "" and client: {} to the createEnv call:

export const env = createEnv({
  clientPrefix: "",
  client: {},
  server: {
    DATABASE_URL: z.string().min(1),
    // ...
  },
  runtimeEnv: process.env,
  emptyStringAsUndefined: true,
});

2. Runtime module resolution failure on Vercel

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/apps/server/node_modules/@fuelops-v2/api/src/context.ts'

Root cause: Workspace packages (packages/api, packages/auth, packages/db) export raw .ts files via their exports field. Vercel's runtime tries to resolve these at runtime but Node.js cannot import .ts files natively. The tsdown build bundles workspace packages (via noExternal), but Vercel ignores the bundle and runs the source directly.

3. No Vercel deployment configuration included

The generated project has no vercel.json or deployment setup for the Hono server. Vercel's zero-config Hono detection doesn't work with this monorepo structure because of the workspace .ts import issue above.

Solution Required

To deploy the Hono server to Vercel, all of the following are needed:

  1. Fix the env type inference — add clientPrefix: "" and client: {} to server env config
  2. Bundle all dependencies in tsdown — change noExternal: [/@fuelops-v2\/.*/] to noExternal: [/^(?!node:)/] so the output is fully self-contained
  3. Create a Vercel entry point (src/vercel.ts) that adapts Hono to Node.js (IncomingMessage, ServerResponse) handler format
  4. Add a second tsdown entry for the Vercel handler
  5. Use the Vercel Build Output API — create .vercel/output/ structure with a script, since buildCommand and builds in vercel.json conflict
  6. Add vercel.json with buildCommand, framework: null

Suggested Fix

Consider adding a Vercel deployment option to the CLI that generates:

  • A vercel.json with proper buildCommand and framework: null
  • A src/vercel.ts entry point with the Node.js ↔ web standard adapter
  • A scripts/prepare-vercel.mjs Build Output API setup script
  • Updated tsdown.config.ts with full dependency bundling
  • The clientPrefix fix in the env package

Or at minimum, document these deployment requirements for Vercel.

Environment

  • create-better-t-stack version: latest (as of Feb 2026)
  • Node.js: 24.13.0 (Vercel build environment)
  • TypeScript: 5.9.3
  • Vercel CLI: 50.18.2

Activity

  1. duwscan commented on Mar 26, 2026

    @duwscan

    Same here

  2. marcusthuressonn commented on Mar 27, 2026

    @marcusthuressonn

    @KingJune28 did you get it to work on your end? I cannot get it to work on my end, do you have a repo that I can have a look at?

  3. AmanVarshney01 commented on Oct 21, 2026

    @AmanVarshney01
    Owner

    Vercel deploys of a separate Hono server in the monorepo were fixed end to end in #1261 (startup crash, /api 404s, module resolution). The old env package was replaced by Varlock in #1224. If you still see this on the latest version, please reopen or open a new issue with the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions