Nitro Bun preset fails on Vercel (dist missing) while plain Nitro crashes at runtime
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
-
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).
-
-
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
.outputdidn’t help. - Railway deployments (Node runtime) work fine with the same code.
Logs
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?
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?
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
So this is nothing bun specific i guess?