Discover why Vercel builds fail without key configs. Follow our step-by-step guide to deploy lovable apps and master best practices.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Deploys fail because Vercel needs specific build/runtime configuration and environment variables that Lovable’s dev preview does for you implicitly. Without explicit project files (vercel.json or correct package.json scripts), a declared Node engine, and a clear mapping of Secrets → Vercel env names, Vercel either runs the wrong builder, uses the wrong output folder, or lacks required secrets at build/runtime — causing failed builds or 500s.
Prompt A — create or update vercel.json intelligently
// Inspect package.json. If dependency "next" exists, create vercel.json using @vercel/next; otherwise use @vercel/static-build.
// Create file vercel.json at project root with the following content depending on the framework.
{
"version": 2,
"builds": [
// if using Next.js:
// {"src":"package.json","use":"@vercel/next"}
// otherwise:
{"src":"package.json","use":"@vercel/static-build"}
],
"routes": [
// basic rewrite to SPA index for client-side routing
{"src":"/_next/static/(.*)","headers":{"cache-control":"public, max-age=31536000, immutable"}},
{"src":"^/(.*)$","dest":"/index.html"}
]
}
Prompt B — ensure package.json has build/start scripts and Node engine
// Update package.json at project root.
// Ensure there is a "build" script that matches your framework, add a "start" for Node if needed, and pin Node engine.
{
// modify "scripts": add or update the "build" entry to match framework, e.g. "next build" or "react-scripts build"
"scripts": {
"build": "next build",
"start": "next start"
},
// add engines to specify Node version
"engines": {
"node": "18.x"
}
}
Prompt C — add a developer-facing note mapping Lovable Secrets to Vercel envs
// Create file .lovable/vercel-env-mapping.md describing exact env var names required.
// Explain that Lovable Secrets must be set in Lovable for preview, and the SAME NAMES must be added manually in Vercel dashboard (outside Lovable).
// Include a checklist of variable names and whether they are needed at build or runtime.
# Vercel env mapping
// Example entries:
- NEXT_PUBLIC_API_URL // required at build/runtime
- DATABASE_URL // required at build and runtime (do not expose to client)
- SUPABASE_KEY // runtime only
// NOTE: Add these keys in Vercel Project Settings > Environment Variables. Lovable Secrets do NOT sync to Vercel automatically.
Important external steps (outside Lovable)
This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.
Yes. Use Lovable to add the minimal Vercel config and build scripts, create an .env.example, save secrets with Lovable’s Secrets UI, export/sync the project to GitHub from Lovable, then import that GitHub repo into Vercel and deploy. Below are copy-paste-ready Lovable prompts that will make the repository ready for Vercel and produce a short DEPLOYMENT.md explaining the final Vercel UI steps.
Please update package.json at the project root. If package.json exists, edit its "scripts" to include build/dev/start entries for a Next.js app. If it doesn't exist, create one.
Write package.json with these fields (preserve existing other fields if present):
{
"name": "my-lovably-app",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p $PORT"
},
"dependencies": {
"next": "13.x",
"react": "18.x",
"react-dom": "18.x"
}
}
Also commit this change and create a short git commit message: "Add Next.js build scripts for Vercel".
Create vercel.json at the project root with a simple configuration to pin Next handling and a readable default. This is optional for many Next apps but helpful to be explicit.
Create file vercel.json with:
{
"version": 2,
"builds": [
{ "src": "package.json", "use": "@vercel/next" }
]
}
Commit as "Add vercel.json".
Create .env.example at the project root listing env var names your app expects (do not include secrets). Example for a typical app — edit keys to match your app:
// .env.example
NEXT_PUBLIC_API_URL=
DATABASE_URL=
ANOTHER_SECRET_KEY=
Also create DEPLOYMENT.md with precise steps for using Lovable + GitHub + Vercel. Put the contents below into DEPLOYMENT.md:
# Deployment steps (Lovable -> GitHub -> Vercel)
// 1) In Lovable: open Publish -> Export to GitHub (or enable GitHub sync) and push this repository to a GitHub repo.
// 2) In Lovable: use Secrets UI to create values for the variable names in .env.example (these are for local Preview and source control safety).
// 3) In Vercel: import the GitHub repository, choose the root folder, and set the same environment variables in Vercel's Dashboard for Preview/Production.
// 4) Deploy from Vercel; Vercel will run `npm run build` automatically.
Commit as "Add .env.example and DEPLOYMENT.md".
Ensure the repo is clean and committed in Lovable. Create a final commit "Prepare for Vercel deploy" that bundles package.json, vercel.json, .env.example, and DEPLOYMENT.md.
Then prompt the user action: "Please click Publish -> Export to GitHub (or enable GitHub sync) in Lovable to push this project to a new GitHub repository."
Create a short note file at docs/VERCEL_IMPORT.md that tells the person deploying to do these steps in Vercel Dashboard (these steps cannot be executed inside Lovable):
// docs/VERCEL_IMPORT.md
1. Go to https://vercel.com/new and choose "Import Git Repository".
2. Connect your GitHub account and select the repo you exported from Lovable.
3. For Build Command leave as "npm run build" and Output Directory empty for Next.js.
4. In Environment Variables section, add entries that match keys in .env.example. Paste the secret values from Lovable Secrets UI into Vercel's dashboard.
5. Finish import and click Deploy.
Commit as "Add Vercel import instructions".
Notes
Keep Node & build config pinned, surface secrets only via Lovable Secrets (and mirror them into Vercel when you connect via GitHub), make builds deterministic (engines/.nvmrc + package.json), add a small vercel.json for headers, function limits, and caching, set Next.js to standalone output (if using Next) and explicit image domains, exclude Lovable-local files with .vercelignore, and use Lovable Preview + GitHub export to validate before connecting Vercel. These changes reduce surprises when Vercel builds your Lovable project.
Please make these repository edits:
create file .nvmrc at project root with this exact content:
// pin Node to a LTS major (choose 18 or 20 based on your app)
18
update package.json (root) to include an engines entry and stable scripts. Replace or merge into package.json:
// add or update these fields in package.json
"engines": {
"node": ">=18 <=20"
},
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"preview": "next build && next start"
}
Please create vercel.json in project root with this content (adjust memory/duration values to your needs):
// vercel.json controls routes, headers, and serverless function defaults
{
"version": 2,
"functions": {
"api/**/*.js": {
"memory": 1024,
"maxDuration": 10
},
"api/**/*.ts": {
"memory": 1024,
"maxDuration": 10
}
},
"headers": [
{
"source": "/(.*)\\.(js|css|png|jpg|svg|json)",
"headers": [
{ "key": "Cache-Control", "value": "public, max-age=31536000, immutable" }
]
}
]
}
If you use Next.js, update next.config.js (root) to make production output more Vercel-friendly. Edit or create file with:
// minimal Next config with standalone output and common production flags
module.exports = {
reactStrictMode: true,
swcMinify: true,
productionBrowserSourceMaps: true,
output: "standalone",
images: {
// list domains you use (e.g., supabase storage or external CDNs)
domains: ["your-supabase-storage-url.com", "cdn.example.com"]
}
};
Create .vercelignore to avoid shipping unnecessary files to Vercel:
// ignore local tooling, Lovable drafts, and node_modules (Vercel installs deps)
lovable/
.idea/
.vscode/
*.local
.env.local
.env.development
.DS_Store
tests/
Create .env.example (root) and a short deploy doc docs/DEPLOY_VERCEL.md. Please add these files:
.env.example:
// list the environment variable names — do NOT include secrets
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_ANON_KEY=
SUPABASE_SERVICE_ROLE_KEY=
docs/DEPLOY_VERCEL.md:
// instructions for operators — use Lovable Secrets UI and GitHub export
// 1) Use Lovable Secrets UI to store SUPABASE_SERVICE_ROLE_KEY and other secrets.
// 2) Export/sync repository to GitHub, then connect the GitHub repo to Vercel.
// 3) In Vercel dashboard, add matching environment variables (copy names from .env.example).
// 4) Use Lovable Preview to validate build before publishing to GitHub.
From startups to enterprises and everything in between, see for yourself our incredible impact.
Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We’ll discuss your project and provide a custom quote at no cost.