nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Nitro Bun preset fails on Vercel (dist missing) while plain Nitro crashes at runtime

Open vdmkotai opened this issue 1 month ago • 4 comments

Environment

Environment

  • Bun 1.3.2
  • Vercel project using Bun runtime
  • Nitro ^3.0.1-alpha.1, TanStack React Start ^1.132.31, Vite ^7.0.2
  • Deployment URL example: <your-deployment-url>
  • Logs show internal error right after [env] VITE_SERVER_URL resolved … (no additional stack trace).

Reproduction

  1. Repo configured with:

    • Scripts

      { "dev": "bun --bun vite dev", "build": "bun --bun vite build", "serve": "bun --bun vite preview" }

      • Vite config

      export default defineConfig({ plugins: [ tsconfigPaths(), tailwindcss(), tanstackStart(), nitro({ preset: "bun" }), viteReact(), ], }); 2. Push to Vercel (Bun runtime).

  2. Build fails with “dist directory not found”. If I remove { preset: "bun" }, build succeeds but runtime 500s when Vercel starts the server.

Describe the bug

Summary I’m running a TanStack React Start app with Vite and Nitro.

This is an app I'm trying to deploy (with my neon db an redis configured): https://github.com/vdmkotai/tanstack-faster

When I run the Vite scripts via Bun (bun --bun vite dev|build|preview) using plain nitro() in vite config - everything builds but the serverless runtime on Vercel crashes immediately.

If I switch Nitro to nitro({ preset: "bun" }) the Vercel build itself crashes saying it can’t find dist folder

Meanwhile, everything works perfectly on Railway.

Additional context

Additional Context

  • Manually switching Vercel’s output folder to .output didn’t help.
  • Railway deployments (Node runtime) work fine with the same code.

Logs


vdmkotai avatar Nov 18 '25 19:11 vdmkotai

Thanks for detailed issue.

For deploying to vercel, you should not have preset: bun config so that it can generate proper build output.

Can you check your functions tab when function crashes what it says?

pi0 avatar Nov 18 '25 19:11 pi0

UPD: After I posted this on X, Bun updated their docs

The new recommended way is to use

export default defineConfig({
  plugins: [
    tanstackStart(),
    nitro({
      vercel: { 
        functions: { 
          runtime: "bun1.x", 
        }, 
      }, 
    }),
  ],
});

I tried, but unfortunately it also didn't help

@pi0 as I said, I tried all three optons:

  • plain nitro()
  • nitro({ preset: "bun" })
  • and now the one I mentioned above (from updated bun docs)

None is working

As for functions tab - not sure what tab do you mean

This one?

Image

vdmkotai avatar Nov 20 '25 10:11 vdmkotai

I guess the problem is how Vercel or Nitro bundles environment variables.

I need dynamic runtime variables (like VITE_SERVER_URL) for server-side image prefetching, where the URL changes depending on the environment (preview vs production).

Again - on Railway it was totally fine

I was able to fix it by using https://github.com/t3-oss/t3-env

Here's the commit that finally made it work. https://github.com/vdmkotai/tanstack-faster/commit/2afe44598922ccef67d529cd1d81a2d8e39dcdcd#diff-4ebb1483bb81cb9efb8a047783b4bae57c9fa999ff30d63399a82577714d901f

vdmkotai avatar Nov 20 '25 13:11 vdmkotai

So this is nothing bun specific i guess?

pi0 avatar Nov 20 '25 16:11 pi0