Chapter 9
Deploying Your Site with Vercel
So far your site has only run on your computer, at localhost:3000. In this chapter it gets a real address on the internet, one you can send to the whole family.
We'll use Vercel, a hosting service built by the company that develops Next.js. The best part: after a one-time connection to GitHub, every push to main updates the site on its own, without clicking any button.
How it works: the flow
Before you start clicking, it's worth understanding the big picture:
| # | What happens | Where |
|---|---|---|
| 1 | You (or Claude) push a change to GitHub | Your computer |
| 2 | GitHub tells Vercel there's new code | GitHub |
| 3 | Vercel downloads the code and runs npm run build | Vercel's servers |
| 4 | If the build succeeds, the new version goes live | The internet |
| 5 | If the build fails, the previous version stays live | The internet |
Notice row 5: a failed deployment doesn't break the site. Visitors keep seeing the last version that worked.
Vercel distinguishes between two kinds of deployments:
| Kind | When it's created | The address | Why it's useful |
|---|---|---|---|
| Production | A push to the main branch | The site's main address | This is the site everyone sees |
| Preview | A push to any other branch, or a pull request | A temporary, separate address for each deployment | Check a change live before it reaches main |
This connects exactly to the workflow from chapter 8: branch → pull request → a Vercel preview → merge → the site updates.
Step 0: Check before deploying
Before connecting, make sure the project is ready. Claude can do most of the check:
We're about to deploy the site to Vercel. Check that the project is ready: npm run build passes, every package in use is listed in package.json, there are no passwords or keys in the code, .env files are in .gitignore, and there's no code that relies on files that exist only on my computer. Show me a list of what you found, and don't fix anything yet
Ready to deploy?
0 of 4
Step 1: Connect GitHub to Vercel
1.1 Create an account
- Go to vercel.com and click Sign Up.
- Choose the Hobby plan, the free plan.
- Choose Continue with GitHub and sign in with your GitHub account. That way Vercel can access your repositories.
1.2 Import the project
- In the Vercel dashboard, click Add New... → Project.
- Under Import Git Repository a list of your GitHub repositories appears. Find
grandma-recipesand click Import. - The repository isn't listed? Click the link for configuring GitHub access (worded something like Adjust GitHub App Permissions), and in GitHub's window grant Vercel access to this repository.
1.3 The settings screen
After the import, a Configure Project screen appears. In most projects you don't need to change anything there:
| Field | What to choose | Explanation |
|---|---|---|
| Project Name | grandma-recipes | Determines the address: grandma-recipes.vercel.app (if the name is taken, Vercel adds a suffix) |
| Framework Preset | Next.js | Vercel detects this on its own |
| Root Directory | ./ | The folder the project is in. Change it only if the project is in a subfolder of the repository |
| Build and Output Settings | Leave as is | The build command (npm run build) and other settings are detected automatically |
| Environment Variables | Empty, for now | More on this in step 2 |
Click Deploy.
1.4 The first deployment
Vercel starts building, and you'll see the Build Logs running in real time. They look just like what you saw when you ran npm run build yourself:
Cloning github.com/your-username/grandma-recipes (Branch: main)
Running "npm install"
added 312 packages in 14s
Running "npm run build"
▲ Next.js 15.5.4
✓ Compiled successfully
✓ Generating static pages (11/11)
Build Completed in /vercel/output [42s]
Deploying outputs...
Deployment completedAfter a minute or two a celebratory screen appears with a screenshot of the site. Click it, or Continue to Dashboard. Your site is live, at an address like:
https://grandma-recipes.vercel.appOpen the link on your phone too. That's the site you built, on the internet, for the whole world.
Step 1: the site is live
0 of 5
1.5 Testing the automatic deployment
Now the cool part. Go back to Claude Code and ask for a small change:
Change the opening sentence on the home page to “Welcome to Grandma's kitchen”, commit it to git and push to main
After the push, go to the project's Deployments tab on Vercel. You'll see a new deployment that started on its own. When it finishes, refresh the site: the new sentence is already there.
Step 2: Environment variables and build settings
What are environment variables?
Environment variables are settings the code needs, but that aren't stored in the code itself. Mostly these are secret things, like an API key or a database password, and things that differ between environments, like the site's address.
On your computer they live in a file called .env.local, which doesn't go to GitHub, because it's in .gitignore:
SITE_NAME="Grandma's Recipes"
CONTACT_EMAIL="family@example.com"
NEXT_PUBLIC_SITE_URL="http://localhost:3000"Since this file doesn't reach GitHub, Vercel doesn't see it either. So you need to set the variables in Vercel too.
Add variables in Vercel
- In the project dashboard, click Settings → Environment Variables.
- Enter the variable's name (Key) and its value (Value).
- Choose which environments it belongs to:
- Production: the main site.
- Preview: previews of branches and PRs.
- Development: for anyone pulling the variables to their computer with Vercel's command-line tool.
- Click Save.
- Important: new variables apply only to new deployments. To make the current site know about them, go to Deployments, click the three dots (...) next to the latest deployment, and choose Redeploy.
Claude can help you sort this out:
Go through the code and make a list of every environment variable the project uses. For each variable: whether it's secret, whether it must be available in the browser (and therefore start with NEXT_PUBLIC_), and what its value should be in production. Also create a .env.example file with the names only, no real values, so there's documentation in the project
Build settings
In most projects Vercel detects everything on its own. If you do need to change something, the settings are under Settings → Build and Deployment (in older interfaces: General):
| Setting | Next.js default | When to change |
|---|---|---|
| Build Command | npm run build | If you have a special build script |
| Install Command | npm install (detected from the lock file) | Almost never |
| Output Directory | Detected automatically | Almost never |
| Root Directory | ./ | If the project is in a subfolder of the repository |
| Node.js Version | A recent supported version | If the build fails because of the version, it should match the version on your computer (node -v) |
Step 2: variables and settings
0 of 5
Step 3: Your own domain
grandma-recipes.vercel.app works great, but grandma-recipes.com looks much better. Here's how to connect it.
3.1 Buy a domain
You buy a domain from a domain registrar. There are many, for both generic endings like .com and country endings like .co.uk, and Vercel itself sells domains too. A domain's yearly price usually ranges from a few dollars to a few dozen, depending on the ending.
3.2 Add the domain in Vercel
- In the project, go to Settings → Domains.
- Click Add Domain, type the domain (for example
grandma-recipes.com) and click Add. - Vercel asks how to handle the
wwwversion. The recommendation: add both, and redirect one to the other, so both addresses work. - Vercel shows DNS records you need to set at your registrar, with a warning sign until they're set.
3.3 Set DNS at the registrar
DNS is the internet's "phone book": it tells browsers where to go when someone types your domain. You need to add two records at your registrar, according to what Vercel shows:
| Record type | Name / Host | Value | For |
|---|---|---|---|
| A | @ | An IP address Vercel shows, usually 76.76.21.21 | The main domain: grandma-recipes.com |
| CNAME | www | An address Vercel shows, something like cname.vercel-dns.com | The www version |
3.4 Wait, and check
- DNS changes usually take a few minutes to a few hours, and in rare cases up to 48 hours.
- When everything is set correctly, the sign next to the domain in Vercel turns into a green check (Valid Configuration).
- Vercel issues a security certificate (HTTPS) automatically and for free. The padlock in the address bar appears without you doing anything.
Step 3: domain
0 of 5
Step 4: Check the live site
The live site isn't exactly the site on your computer: different servers, a different operating system, different environment variables. So you go over it again, this time at the real address.
The manual check
Live check
0 of 7
Logs in Vercel
If something doesn't work live, Vercel provides two kinds of logs:
| Log | Where | What you see in it |
|---|---|---|
| Build Logs | Deployments → click a deployment | Everything that happened during the build, including errors |
| Runtime Logs | The project's Logs tab | Errors that happen while visitors use the site, on the server side |
Claude as a tester of the live site
The site is live at [your address]. Prepare an organized checklist for the live site: every page, every interactive feature, edge cases, and what to check on a phone. For each check: what to do and what should happen
Step 5: When a deployment fails
It'll happen at some point, and there's no reason to panic: the live site isn't affected. Vercel simply doesn't replace it with the broken version.
Find the error
- In the Deployments tab, the failed deployment is marked in red, with the word Error.
- Click it and open the Build Logs.
- Scroll to the red lines, usually near the end, and copy the whole error.
- Paste it to Claude, just like in chapter 7:
Weak prompt
Vercel failed, fix it
Strong prompt
The Vercel deployment failed, but npm run build passes on my computer. Here's what the Build Logs show: [paste the whole error]. Explain why it works for me and not on Vercel, and fix the root cause. After the fix, run npm run build on my machine to confirm, and push.
"But it works for me!": the usual suspects
| Cause | What it looks like in the log | The fix |
|---|---|---|
| Uppercase vs. lowercase in a file name. Windows and Mac are forgiving, Vercel's servers (Linux) aren't | Module not found: Can't resolve './components/recipeCard' | Fix the file name or the import so they match exactly |
| A missing environment variable | An error about an undefined value, or a failed connection | Set the variable in Vercel (step 2), and redeploy |
A package installed on your machine but not listed in package.json | Module not found: Can't resolve 'some-package' | npm install some-package, commit package.json and package-lock.json, and push |
A file that's in .gitignore and the code needs it | A missing file | Understand why it's there. If it's secret, turn it into an environment variable |
| A different Node.js version | An error mentioning engine or Node.js version | Align the Node.js version in the build settings (step 2) |
| A regular build error that wasn't checked locally | Type error or a lint error | npm run build on your machine before every push (chapter 7) |
The live site is broken? Go back in a second
Sometimes the deployment succeeds, but something on the site doesn't work right. In that case you don't need to wait for a fix:
- Go to Deployments.
- Find the last deployment that worked well.
- Click the three dots (...) and choose Instant Rollback (or Promote to Production, depending on the interface and plan).
The site goes back to the previous version within seconds. Now you can fix it calmly, with Claude, and push when the fix is ready and tested.
Advanced: Vercel from the terminal
Vercel also has a command-line tool, which lets Claude work with Vercel directly. It's optional, since the Git flow we built is enough, but it's handy for environment variables and checking deployments:
npm install -g vercel
vercel loginvercel link # links the folder to a Vercel project
vercel env pull # downloads the environment variables to .env.local
vercel ls # shows the latest deploymentsSummary
- One-time connection: Vercel → Import → a GitHub repository → Deploy. From then on, every push to main updates the site, and every branch or PR gets a preview address.
- Environment variables are set under Settings → Environment Variables, for the right environments, followed by a redeploy. Secrets never go in
NEXT_PUBLIC_. - Domain: Settings → Domains, then DNS records at the registrar exactly as Vercel shows. HTTPS comes on its own.
- Live check: a manual checklist, Build Logs and Runtime Logs.
- When it fails: the previous site stays live. Copy the error from the Build Logs to Claude, and check the usual suspects. When the live site is broken: Instant Rollback, then a fix in Git.
In the next chapter we'll collect pro tips: how to save on costs, upgrade CLAUDE.md and connect external tools with MCP, and wrap up everything we've learned.
Check yourself
1. The Vercel deployment failed. What happens to the live site?
2. Where should you never put an API key?
Answering every quiz question marks the chapter as done automatically.