Deploy a Bun application on Vercel
Vercel is a cloud platform for building, deploying, and scaling apps. Vercel Functions can run on the Bun runtime, either behind a framework that Vercel supports or as a Bun.serve() server.
- Configure Bun in vercel.json
To run your Functions on Bun, add a
bunVersionfield to yourvercel.jsonfile:vercel.json{ "bunVersion": "1.4.x" // [!code ++] }Vercel manages the patch version.
For best results, match your local Bun version with the version Vercel uses.
- Add a server
Choose how requests reach your code.
Vercel's Bun framework preset sends every request for the deployment to a single
Bun.serve()server. Vercel uses the preset when the project setsbunVersion, has abun.lockfile, and has a server entrypoint at one of these paths:server.{js,cjs,mjs,ts,cts,mts}src/server.{js,cjs,mjs,ts,cts,mts}
bun installcreatesbun.lockon Bun 1.2 or later. On older versions, runbun install --save-text-lockfile. The preset does not detect the binarybun.lockbformat.Call
Bun.serve()once while the module loads. Vercel detects that call and routes incoming requests to it. Vercel supports thefetch,routes,error, andwebsocketoptions:server.ts
Bun.serve({ routes: { "/health": () => Response.json({ status: "ok" }), }, fetch() { return new Response("Hello from Bun on Vercel"); }, });A minimal project is
package.json,bun.lock,server.ts, and thevercel.jsonfrom the previous step. It doesn't need anapi/directory or any routing configuration.To add a Bun server to a project that also has a frontend, create
api/server.tsand callBun.serve()once while the module loads. Vercel deploys it as a single Function at/api/server. Unlike the framework preset, only requests for/api/serverreach this server.api/server.ts
Bun.serve({ fetch(request) { const url = new URL(request.url); return Response.json({ message: "Hello from Bun on Vercel", pathname: url.pathname, }); }, });This setup only needs the
bunVersionsetting from the previous step; it doesn't use the framework preset or require abun.lockfile. To send other paths to this server, add route overrides tovercel.json. Each override must use the full request path, including the/api/serverprefix. See the Vercel Bun runtime documentation for details.Frameworks that Vercel supports, such as Next.js, Express, Hono, and Nitro, run on Bun once you set
bunVersion.If you're deploying a Next.js project (including ISR), also update the
package.jsonscripts so the Next.js CLI runs under Bun:package.json{ "scripts": { "dev": "bun --bun next dev", // [!code ++] "build": "bun --bun next build" // [!code ++] } } - Deploy your app
Connect your repository to Vercel, or deploy from the CLI:
terminal# Using bunx (no global install) bunx vercel login bunx vercel deployOr install the Vercel CLI globally:
terminalbun i -g vercel vercel login vercel deploy - Verify the runtime
To confirm your deployment uses Bun, log the Bun version:
server.ts
console.log("runtime", process.versions.bun);Textruntime 1.4.0See the Vercel Bun Runtime documentation for feature support →
- Fluid compute: Both Bun and Node.js runtimes run on Fluid compute and support the same core Vercel Functions features.
- Middleware: To run Routing Middleware with Bun, set the runtime to
nodejs:
export const config = { runtime: "nodejs" }; // [!code ++]