Vercel Deployment Automation
Deploy any project to Vercel from the CLI — preview and production deployments, prebuilt output, environment variables, framework detection, team scoping, and CI/CD integration patterns.
Content
Deploy any project to Vercel from the command line. Always deploy as preview (not production) unless the user explicitly asks for production. Preview deployments get unique URLs, do not affect your live site, and can be promoted to production later.
Prerequisites
Check whether the Vercel CLI is installed without escalated permissions:
If missing, install it globally:
For CI environments, authenticate with a token instead of interactive login:
Preview Deployments
Preview is the default and the safe choice. Each preview deployment gets a unique URL tied to that specific build.
The -y flag confirms the default project settings without prompting. Vercel auto-detects the framework (Next.js, Remix, Astro, SvelteKit, etc.) and applies the correct build settings.
Important: Use a 10-minute (600,000ms) timeout for the deploy command. Builds can take several minutes depending on project size and framework.
Production Deployments
Only deploy to production when explicitly requested:
The promote pattern is safer for CI — deploy a preview, run tests against the preview URL, then promote only if tests pass.
Prebuilt Output
If you build locally or in CI before deploying, skip Vercel's build step entirely with --prebuilt. This is faster and gives you full control over the build:
This is particularly useful for monorepos or projects with complex build pipelines that Vercel's build system cannot handle natively.
Environment Variables
Manage environment variables per deployment environment (production, preview, development):
For CI, set secrets as environment variables in your CI provider and pass them during deploy:
Team and Project Scoping
When working across multiple teams or projects:
Framework-Specific Patterns
Next.js
Static Sites (Astro, Hugo, etc.)
Monorepo with Root Config
CI/CD Integration
GitHub Actions
Deploy-Test-Promote Pattern
Fallback: No Auth or CLI Unavailable
If the CLI fails with "No existing credentials found" or is not installed, use the deploy script:
The script handles framework detection, packaging, and deployment. It returns JSON with previewUrl and claimUrl. Tell the user: "Your deployment is ready at [previewUrl]. Claim it at [claimUrl] to manage your deployment."
Deployment Inspection
Troubleshooting
Sandbox network access: If deployment fails due to network issues (timeouts, DNS errors), the deploy command needs escalated network access. Rerun with sandbox_permissions=require_escalated. Do not escalate the command -v vercel check — only the actual deploy.
Build failures: Check logs with vercel logs <url>. Common causes: missing environment variables, incorrect Node.js version, or framework misconfiguration.
Authentication errors: For CI, always use --token. For local, run vercel login to re-authenticate. Tokens can be created in the Vercel dashboard under Account Settings > Tokens.
Timeout issues: Large projects may exceed default timeouts. Set explicit timeouts in your CI configuration (10 minutes minimum).
Do not curl or fetch the deployed URL to verify it works. Just return the link to the user.
FAQ
Discussion
Loading comments...