> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/oven-sh/bun/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy to Vercel

> Deploy a Bun application to Vercel using the Bun runtime for Vercel Functions, including configuration, Next.js support, and environment variables.

[Vercel](https://vercel.com/) is a cloud platform for deploying and scaling web applications.

<Warning>
  The Bun runtime on Vercel is in Beta. Certain features — such as automatic source maps, byte-code caching, and metrics on `node:http/https` — are not yet supported.
</Warning>

<Note>
  `Bun.serve` is not supported on Vercel Functions. Use Bun with a framework supported by Vercel, such as Next.js, Express, Hono, or Nitro.
</Note>

<Steps>
  <Step title="Configure Bun in vercel.json">
    To enable the Bun runtime for your Vercel Functions, add a `bunVersion` field to your `vercel.json`:

    ```json vercel.json theme={null}
    {
      "bunVersion": "1.x"
    }
    ```

    Vercel automatically detects this configuration and runs your functions on Bun. The value must be `"1.x"` — Vercel manages the minor version internally. For best results, match your local Bun version with the version used by Vercel.
  </Step>

  <Step title="Set Bun as the package manager (optional)">
    To ensure Vercel uses Bun to install dependencies, set `packageManager` in `package.json`:

    ```json package.json theme={null}
    {
      "packageManager": "bun@1.x"
    }
    ```

    Alternatively, add `ENABLE_BUN_INSTALL=1` as an environment variable in the Vercel dashboard.
  </Step>

  <Step title="Configure Next.js scripts (if applicable)">
    If you are deploying a Next.js project, update your `package.json` scripts to use the Bun runtime by prefixing Next.js CLI commands with `bun --bun`:

    ```json package.json theme={null}
    {
      "scripts": {
        "dev": "bun --bun next dev",
        "build": "bun --bun next build",
        "start": "bun --bun next start"
      }
    }
    ```

    <Note>
      The `--bun` flag runs the Next.js CLI under Bun's runtime. Bundling (via Turbopack or Webpack) is unchanged, but all lifecycle commands execute within Bun.
    </Note>
  </Step>

  <Step title="Set environment variables">
    Configure environment variables in the Vercel dashboard under **Project Settings → Environment Variables**, or via the CLI:

    ```bash theme={null}
    vercel env add DATABASE_URL
    vercel env add API_SECRET
    ```

    Access them at runtime using `process.env` or `Bun.env`:

    ```typescript theme={null}
    const dbUrl = process.env.DATABASE_URL;
    const secret = Bun.env.API_SECRET;
    ```
  </Step>

  <Step title="Deploy your app">
    Connect your repository to Vercel via the dashboard, or deploy from the CLI using `bunx`:

    ```bash theme={null}
    # Using bunx (no global install required)
    bunx vercel login
    bunx vercel deploy
    ```

    Or install the Vercel CLI globally with Bun:

    ```bash theme={null}
    bun i -g vercel
    vercel login
    vercel deploy
    ```
  </Step>

  <Step title="Verify the runtime">
    To confirm your deployment is running on Bun, log the runtime version:

    ```typescript index.ts theme={null}
    export default function handler(req: Request) {
      return new Response(`Running on Bun ${process.versions.bun}`);
    }
    ```

    The response should read something like `Running on Bun 1.3.3`.
  </Step>
</Steps>

## Serverless function example

Here is an example Vercel Function using Bun's native `Request`/`Response` API:

```typescript api/hello.ts theme={null}
export default function handler(req: Request) {
  const url = new URL(req.url);
  const name = url.searchParams.get("name") ?? "World";
  return new Response(`Hello, ${name}!`);
}
```

## Additional notes

* **Fluid compute**: Both Bun and Node.js runtimes run on Vercel's Fluid Compute and support the same core Vercel Functions features.
* **Middleware**: Routing Middleware must use the `nodejs` runtime:

```typescript middleware.ts theme={null}
export const config = { runtime: "nodejs" };
```

<Tip>
  See the [Vercel Bun Runtime documentation](https://vercel.com/docs/functions/runtimes/bun) for the full feature support matrix.
</Tip>
