Skip to content
Docs

Using the Bun Runtime with Vercel Functions

The Bun runtime is available in Beta on all plans

Bun is a fast, all-in-one JavaScript runtime that serves as an alternative to Node.js.

Bun provides Node.js API compatibility and is generally faster than Node.js for CPU-bound tasks. It includes a bundler, test runner, and package manager.

For all frameworks, including Next.js, you can configure the runtime in your vercel.json file using the bunVersion property.

Once you configure the runtime version, Vercel manages the patch versions automatically. Currently, "1.4.x" and "1.x" are the only valid versions:

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

Vercel manages the Bun minor versions automatically. 1.4.x and 1.x are the only valid values currently.

Use the Bun framework preset when you want one Bun.serve() server to route requests for your application. After you configure bunVersion in vercel.json, add a bun.lock file and a server entrypoint in the project root or the src/ directory:

  • server.{js,cjs,mjs,ts,cts,mts}
  • src/server.{js,cjs,mjs,ts,cts,mts}

With Bun 1.2 or later, run bun install to create bun.lock. For older versions, run bun install --save-text-lockfile. The preset doesn't detect the legacy bun.lockb format.

A minimal project contains package.json, bun.lock, server.ts, and the vercel.json configuration shown above. You don't need an /api directory or routing configuration.

Call Bun.serve() once during module startup. Vercel uses that call to detect the server, then routes incoming requests through a Vercel Function. You can use the fetch, routes, error, and websocket options:

server.ts
Bun.serve({
  routes: {
    '/health': () => Response.json({ status: 'ok' }),
  },
  fetch() {
    return new Response('Hello from Bun on Vercel');
  },
});

The port and hostname options only apply when you run the server locally. They don't configure the public endpoint on Vercel. Unix sockets and HTML imports in routes are not supported.

To serve WebSocket connections with Bun.serve(), see the Bun example in the WebSockets documentation.

Create api/server.ts to deploy a native Bun server as one Vercel Function. Vercel serves the function at /api/server, so you can add it to a project that also contains a frontend.

To use custom routing with an /api server, configure route overrides in vercel.json. Each override must use the full request path, including the /api/server prefix.

Call Bun.serve() once during module startup:

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 deployment model only requires the bunVersion configuration shown above. It doesn't use the Bun framework preset or require bun.lock. Unlike the preset, it only sends requests for /api/server to this server.

When using Next.js, and ISR, you must change your build and dev commands in your package.json file to use the Bun runtime:

Before:

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

After:

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

The Bun runtime works with Routing Middleware the same way as the Node.js runtime once you set the bunVersion in your vercel.json file. Note that you'll also have to set the runtime config to nodejs in your middleware.ts file.

The Bun runtime on Vercel supports most Node.js features. The main differences relate to automatic source maps, bytecode caching, and request metrics on the node:http and node:https modules. Request metrics using fetch work with both runtimes.

Vercel Functions using the Bun runtime support large functions with uncompressed bundles up to 5 GB and extended max duration up to 30 minutes. Both features are in beta.

See the table below for a detailed comparison:

Bun Runtime vs Node.js Runtime feature support comparison table
Feature
Bun Runtime
Node.js Runtime
Node.js APIs

Fluid compute

Active CPU

Streaming

waitUntil

Logs

Automatic source maps

Bytecode caching

Request metrics (node:http/https)
Request metrics (fetch)

Vercel Functions using the Bun runtime support most Node.js APIs, including standard Web APIs such as the Request and Response Objects.

Bun is generally faster than Node.js, especially for CPU-bound tasks. Performance varies by workload, and in some cases Node.js may be faster depending on the specific operations your function performs.

Bun is best suited for new workloads where you want a fast, all-in-one toolkit with built-in support for TypeScript, JSX, and modern JavaScript features. Consider using Bun when:

  • You want faster execution for CPU-bound tasks
  • You prefer zero-config TypeScript and JSX support
  • You're starting a new project and want to use modern tooling

Consider using Node.js instead if:

  • Node.js is already installed on your project and is working for you
  • You need automatic source maps for debugging
  • You need request metrics on the node:http or node:https modules

Both runtimes run on Fluid compute and support the same core Vercel Functions features.

Last updated August 24, 2026

Was this helpful?

supported.