0
0
AstroHow-ToBeginner · 4 min read

How to Deploy Astro to Vercel: Step-by-Step Guide

To deploy an Astro project to Vercel, first create a Vercel account and install the Vercel CLI. Then, run vercel in your project folder to deploy, following the prompts to configure your deployment. Vercel automatically detects Astro and builds your site for you.
📐

Syntax

Deploying Astro to Vercel mainly uses the vercel command in your project folder. The basic syntax is:

  • vercel: Starts the deployment process interactively.
  • vercel --prod: Deploys directly to production without prompts.
  • vercel --confirm: Skips confirmation prompts for automated deployment.

Vercel detects your astro.config.mjs and builds your site accordingly.

bash
vercel
vercel --prod
vercel --confirm
💻

Example

This example shows how to deploy a simple Astro project to Vercel using the CLI.

After creating your Astro project and installing dependencies, run vercel in the project root. Follow the prompts to link or create a new Vercel project. Vercel will build and deploy your site, then provide a URL to view it live.

bash
npm create astro@latest my-astro-site
cd my-astro-site
npm install
vercel
Output
Vercel CLI 28.0.0 ? Set up and deploy “my-astro-site”? [Y/n] y ? Which scope do you want to deploy to? YourName ? Link to existing project? [y/N] n ? What’s your project’s name? my-astro-site ? In which directory is your code located? . 🔗 Linked to YourName/my-astro-site (created .vercel) 🔍 Inspect: https://vercel.com/YourName/my-astro-site/abc123 ✅ Production: https://my-astro-site.vercel.app
⚠️

Common Pitfalls

Some common mistakes when deploying Astro to Vercel include:

  • Not running npm install before deploying, causing build failures.
  • Missing astro.config.mjs or misconfigured build settings.
  • Using an outdated Vercel CLI version.
  • Not setting the correct build command or output directory in Vercel settings (usually npm run build and dist).

Always check your package.json scripts and Vercel project settings if deployment fails.

json
{
  "scripts": {
    "dev": "astro dev",
    "build": "astro build",
    "preview": "astro preview"
  }
}
📊

Quick Reference

Summary tips for deploying Astro to Vercel:

  • Run npm install before deploying.
  • Use vercel CLI to deploy interactively.
  • Set build command to npm run build and output directory to dist in Vercel dashboard if needed.
  • Keep astro.config.mjs properly configured.
  • Use vercel --prod for production deploys.

Key Takeaways

Use the Vercel CLI command vercel in your Astro project folder to deploy easily.
Ensure your package.json has a build script running astro build before deploying.
Vercel automatically detects Astro projects and sets build/output settings, but verify if needed.
Run npm install before deploying to avoid build errors.
Use vercel --prod to deploy directly to production without prompts.