🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Deployment••By Komal Nakrani

Deploy Astro to Vercel: Static, SSR and ISR Setup

Deploy Astro to Vercel from Git or the CLI: zero-config static builds, vercel.json redirects and trailing slashes, the @astrojs/vercel adapter, ISR and Web Analytics.

#Astro#Vercel#Deployment#Hosting#SSR

To deploy Astro to Vercel, import the Git repository in the Vercel dashboard and accept the detected Astro framework preset. Vercel runs npm run build, serves the dist/ folder from its CDN, and redeploys on every push, with a preview URL for each branch and pull request. A static Astro site needs no adapter and no vercel.json.

Add the @astrojs/vercel adapter only when routes need to run per request. This guide covers both paths, plus the vercel.json settings and the CLI workflow for CI.

Key Takeaways

  • Static Astro sites are zero-config on Vercel: preset Astro, output dist, no adapter.
  • Set Node.js 22.x in project settings or engines in package.json; Astro 7 needs 22.23.4 or newer.
  • Use vercel.json for redirects, headers and trailingSlash. Vercel doesn’t read _redirects or _headers files.
  • npx astro add vercel adds the adapter for on-demand routes, which run as Vercel Functions.
  • The adapter’s isr option caches on-demand pages and regenerates them in the background.

Deploy Astro to Vercel from Git

  1. Push the project to GitHub, GitLab or Bitbucket.
  2. In Vercel, choose Add New > Project and import the repository.
  3. Vercel detects the Astro framework preset. The build command (npm run build or your build script) and output directory are filled in.
  4. If the project is in a monorepo subfolder, set Root Directory.
  5. Add environment variables if the build needs them.
  6. Select Deploy.

The site is live at <project>.vercel.app within a minute or two. After that:

  • Pushes to the production branch deploy to production.
  • Every other push gets a preview deployment with a unique URL. Vercel comments the link on pull requests.
  • Each deployment is immutable and stays available, so you can roll back by promoting an older one.

Node.js version

Astro 7 requires Node.js 22.23.4 or newer. Set the version in Project Settings > Build and Deployment > Node.js Version, or declare it in package.json, which Vercel respects:

{
  "engines": {
    "node": "22.x"
  }
}

The package.json route keeps the requirement in the repository, where it also documents the version for your team.

Set site for your Vercel domain

// astro.config.mjs
import { defineConfig } from 'astro/config';

export default defineConfig({
  site: 'https://www.example.com',
  trailingSlash: 'always',
});

Use your custom domain once it’s connected; until then, the vercel.app address works. Vercel exposes VERCEL_ENV (production, preview or development) and VERCEL_URL during builds if you need preview-aware URLs, but in most cases you want previews to keep production canonicals so they aren’t indexed.

Configure vercel.json

Vercel doesn’t read Netlify-style _redirects or _headers files. Settings go in vercel.json at the project root:

{
  "trailingSlash": true,
  "redirects": [
    { "source": "/old-blog/:path*", "destination": "/blog/:path*", "permanent": true },
    { "source": "/pricing-2025", "destination": "/pricing/", "permanent": true }
  ],
  "headers": [
    {
      "source": "/_astro/(.*)",
      "headers": [
        { "key": "Cache-Control", "value": "public, max-age=31536000, immutable" }
      ]
    },
    {
      "source": "/(.*)",
      "headers": [
        { "key": "X-Content-Type-Options", "value": "nosniff" },
        { "key": "Referrer-Policy", "value": "strict-origin-when-cross-origin" }
      ]
    }
  ]
}

Trailing slashes

This is the setting most worth getting right. Astro’s default build.format: 'directory' writes about/index.html. Without trailingSlash in vercel.json, Vercel can serve that page at both /about and /about/, which gives search engines two URLs for the same content.

Pick one form and make Astro and Vercel agree:

Astro trailingSlash vercel.json trailingSlash Result
'always' true /about redirects to /about/
'never' false /about/ redirects to /about

Then make sure your canonical tags and internal links use the same form. The trailing slash tip explains the Astro side in more detail.

Redirects: vercel.json or Astro config?

Astro’s redirects option works too. With a static build and no adapter, it generates meta-refresh HTML pages. With the Vercel adapter, Astro turns them into real Vercel redirects. For a static site where the status code matters for SEO, put them in vercel.json. The Astro redirects tip compares the options.

Deploy from the CLI

npx vercel          # preview deployment
npx vercel --prod   # production deployment

The first run links the folder to a Vercel project. For CI, build on your runner and upload the prebuilt output, so the build uses the same environment as your tests:

# .github/workflows/deploy.yml
name: Deploy to Vercel
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
      VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - run: npm install --global vercel
      - run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
      - run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
      - run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}

vercel pull downloads the project settings and environment variables, vercel build runs the build locally into .vercel/output, and vercel deploy --prebuilt uploads that output without rebuilding. If you do this, disable the Git integration’s automatic builds to avoid deploying twice.

Environment variables

Add them under Project Settings > Environment Variables, with separate values for Production, Preview and Development. vercel env pull writes the development values to a local .env file.

As on any host, a static Astro site reads variables only at build time. PUBLIC_ variables are inlined into the output; everything else stays on the build machine. With the adapter, on-demand routes can also read variables at runtime. See the Astro environment variables guide for typed variables with astro:env.

On-demand rendering with @astrojs/vercel

npx astro add vercel
// astro.config.mjs
import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel';

export default defineConfig({
  site: 'https://www.example.com',
  adapter: vercel(),
});

With the adapter, astro build writes Vercel’s Build Output API format to .vercel/output/. Prerendered pages are served as static files from the CDN; routes with export const prerender = false (or every route with output: 'server') run as Vercel Functions. Server Islands, Actions and sessions work once the adapter is in place.

Useful adapter options:

// astro.config.mjs
adapter: vercel({
  webAnalytics: { enabled: true },
  isr: { expiration: 60 * 60 },
  maxDuration: 10,
}),
  • webAnalytics injects Vercel Web Analytics. Enable Analytics in the project dashboard too.
  • isr enables Incremental Static Regeneration: on-demand pages are cached after the first request and regenerated in the background after expiration seconds. You can exclude routes that must always be fresh.
  • maxDuration sets the maximum function run time in seconds, within your plan’s limit.

The ISR on Vercel tip shows how to combine ISR with a CMS webhook, and the official Astro Vercel adapter docs list every option for the current version.

Web Analytics without the adapter

On a static site you can still use Vercel Web Analytics by adding the package’s Astro component to your layout:

npm install @vercel/analytics
---
// src/layouts/BaseLayout.astro
import Analytics from '@vercel/analytics/astro';
---
<html lang="en">
  <head><slot name="head" /></head>
  <body>
    <slot />
    <Analytics />
  </body>
</html>

404 pages

Create src/pages/404.astro. Astro builds dist/404.html, and Vercel serves it with a 404 status for missing paths. With the adapter and on-demand routes, the same page handles not-found responses from server code. The custom 404 page tip has a template.

Custom domains

In Project Settings > Domains, add your domain. Vercel shows the DNS records to create: an A record for an apex domain or a CNAME for a subdomain like www. Certificates are issued automatically. Choose one of the apex or www as primary and let Vercel redirect the other, then update site in astro.config.mjs to the primary and redeploy.

Troubleshooting

Symptom Likely cause Fix
Build fails on astro command Old Node.js Set 22.x in settings or engines
Same page at /about and /about/ No trailingSlash in vercel.json Set it to match Astro’s config
_redirects rules ignored Vercel doesn’t read them Move rules to vercel.json
Function times out Slow API call in an on-demand route Cache the data, or raise maxDuration within plan limits
Canonicals use localhost site not set Set site and redeploy

To roll back, open Deployments, pick a previous production deployment and choose Promote (or Instant Rollback). No rebuild is needed.

Vercel compared with Netlify and Cloudflare Pages

For static Astro output the three hosts are close. Vercel fits teams already deploying other projects there, and its ISR support is the most direct way to cache on-demand Astro pages. Netlify adds built-in forms; Cloudflare adds its storage products and a large network. The Astro deployment guide compares every common host, and the Netlify walkthrough covers the closest alternative.

Komal themes are static Astro 7 projects with no adapter, so they deploy to Vercel on the zero-config path described at the top. The static hosting docs cover Vercel for a theme, and you can browse Astro themes to choose one.

FAQ

Is Vercel free for Astro sites?

Vercel’s Hobby plan is free for personal, non-commercial projects and covers most static Astro sites. Commercial sites need a paid plan under Vercel’s terms, so check the current plan rules before launching a client or business site there.

Do I need @astrojs/vercel to deploy Astro on Vercel?

No. A static Astro site deploys with zero configuration. Install the adapter only for on-demand rendering, ISR, Server Islands, Actions or sessions.

Does Vercel read _redirects files for Astro?

No. _redirects and _headers are Netlify and Cloudflare conventions. On Vercel, define redirects and headers in vercel.json, or use Astro’s redirects option with the adapter.

What is the output directory for Astro on Vercel?

For a static build it’s dist, which the Astro preset sets automatically. With the adapter, Astro writes Vercel’s Build Output API format to .vercel/output/, and Vercel picks that up without extra settings.

Can I use ISR with Astro on Vercel?

Yes. Install @astrojs/vercel, make the routes on-demand, and set the isr option with an expiration in seconds. Vercel caches each page after its first request and regenerates it in the background.