Cloud & deploymentDeploy to Vercel

Deploy to Vercel

Run Vercel Functions on Bun via bunVersion, with Next.js steps and runtime differences

Last updated on

What you get

Vercel Functions execute requests with Bun — not just install dependencies with it. Works with supported frameworks (including Next.js) and standalone functions under /api.

1. Enable the Bun runtime

vercel.json
{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "bunVersion": "1.x"
}

1.x is currently the only valid value; Vercel manages minor and patch versions. Don't pin a minor yourself.

2. The extra Next.js step

Next.js projects using ISR must hand dev / build to Bun:

package.json
{
  "scripts": {
    "dev": "bun run --bun next dev",
    "build": "bun run --bun next build"
  }
}

The app is still bundled by Next.js's own pipeline (Turbopack/Webpack); --bun only changes which runtime executes the commands. Without ISR, confirm against current Vercel docs whether this step is still required.

3. Standalone functions

.ts files under /api compile and run as TypeScript directly:

api/hello.ts
export default {
  async fetch(request: Request) {
    const url = new URL(request.url);
    const name = url.searchParams.get('name') || 'World';
    return Response.json({ message: `Hello ${name}!` });
  },
};

Differences from the Node runtime

  • No automatic source maps, no bytecode caching, and no request metrics on node:http / node:https; fetch metrics work on both runtimes.
  • Most Node.js APIs are supported, but not all; never start Bun.serve inside a Function.
  • Routing Middleware behaves the same as on the Node runtime once bunVersion is set, but the runtime config still says nodejs.

Switching is reversible — test it anyway

Compare cold starts, p95, memory, and error rates on a preview deployment before cutting production over. Rolling back is deleting bunVersion. A stable Node workload doesn't need migrating for uniformity's sake.

Acceptance

  1. Preview function logs confirm Bun is active;
  2. SSR/ISR, streaming responses, Server Functions, and native-dependency paths are covered;
  3. Error stacks remain debuggable without automatic source maps;
  4. The metrics pipeline does not depend on node:http request metrics.

Official references: Vercel Bun runtime, Bun on Vercel.