Your course progress0 of 14 chapters

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 happensWhere
1You (or Claude) push a change to GitHubYour computer
2GitHub tells Vercel there's new codeGitHub
3Vercel downloads the code and runs npm run buildVercel's servers
4If the build succeeds, the new version goes liveThe internet
5If the build fails, the previous version stays liveThe 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:

KindWhen it's createdThe addressWhy it's useful
ProductionA push to the main branchThe site's main addressThis is the site everyone sees
PreviewA push to any other branch, or a pull requestA temporary, separate address for each deploymentCheck 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

  1. Go to vercel.com and click Sign Up.
  2. Choose the Hobby plan, the free plan.
  3. Choose Continue with GitHub and sign in with your GitHub account. That way Vercel can access your repositories.

1.2 Import the project

  1. In the Vercel dashboard, click Add New... → Project.
  2. Under Import Git Repository a list of your GitHub repositories appears. Find grandma-recipes and click Import.
  3. 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:

FieldWhat to chooseExplanation
Project Namegrandma-recipesDetermines the address: grandma-recipes.vercel.app (if the name is taken, Vercel adds a suffix)
Framework PresetNext.jsVercel 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 SettingsLeave as isThe build command (npm run build) and other settings are detected automatically
Environment VariablesEmpty, for nowMore 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:

Vercel build logs (sample output)
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 completed

After 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.app

Open 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:

.env.local (on your computer only)
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

  1. In the project dashboard, click Settings → Environment Variables.
  2. Enter the variable's name (Key) and its value (Value).
  3. 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.
  4. Click Save.
  5. 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):

SettingNext.js defaultWhen to change
Build Commandnpm run buildIf you have a special build script
Install Commandnpm install (detected from the lock file)Almost never
Output DirectoryDetected automaticallyAlmost never
Root Directory./If the project is in a subfolder of the repository
Node.js VersionA recent supported versionIf 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

  1. In the project, go to Settings → Domains.
  2. Click Add Domain, type the domain (for example grandma-recipes.com) and click Add.
  3. Vercel asks how to handle the www version. The recommendation: add both, and redirect one to the other, so both addresses work.
  4. 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 typeName / HostValueFor
A@An IP address Vercel shows, usually 76.76.21.21The main domain: grandma-recipes.com
CNAMEwwwAn address Vercel shows, something like cname.vercel-dns.comThe 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:

LogWhereWhat you see in it
Build LogsDeployments → click a deploymentEverything that happened during the build, including errors
Runtime LogsThe project's Logs tabErrors 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

  1. In the Deployments tab, the failed deployment is marked in red, with the word Error.
  2. Click it and open the Build Logs.
  3. Scroll to the red lines, usually near the end, and copy the whole error.
  4. 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.

“Works for me but not there” is an important clue: it points Claude toward differences between environments, not general bugs in the code.

"But it works for me!": the usual suspects

CauseWhat it looks like in the logThe fix
Uppercase vs. lowercase in a file name. Windows and Mac are forgiving, Vercel's servers (Linux) aren'tModule not found: Can't resolve './components/recipeCard'Fix the file name or the import so they match exactly
A missing environment variableAn error about an undefined value, or a failed connectionSet the variable in Vercel (step 2), and redeploy
A package installed on your machine but not listed in package.jsonModule 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 itA missing fileUnderstand why it's there. If it's secret, turn it into an environment variable
A different Node.js versionAn error mentioning engine or Node.js versionAlign the Node.js version in the build settings (step 2)
A regular build error that wasn't checked locallyType error or a lint errornpm 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:

  1. Go to Deployments.
  2. Find the last deployment that worked well.
  3. 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:

Install and sign in (in a regular terminal)
npm install -g vercel
vercel login
Useful commands
vercel link          # links the folder to a Vercel project
vercel env pull      # downloads the environment variables to .env.local
vercel ls            # shows the latest deployments

Summary

  • 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.