Vercel: Command "npm run build" exited with 1, the real error

Vercel's "Command npm run build exited with 1" only says the build failed. The cause sits a few lines higher in the build log. How to find and fix it.

Simon, Founder of Shipyard

By · Founder of Shipyard

6 minute read

Short answer

Error: Command "npm run build" exited with 1 on Vercel means your own build script stopped with an error. The line itself carries no cause. Vercel's troubleshooting guide says the last mention of "Error" is often not the useful one, and that the real error sits a few lines above it in the build log.

Open the failed deployment, expand Building under Deployment Details, scroll up from the red exit line, fix what that line names, and push again. In apps written by an AI agent the cause is usually a TypeScript error, an import whose letter case differs from the file name, or a variable the build needs but the project does not have.

Where the useful line is

Here is a trimmed log from a Next.js app we will call Tallyhound. The last two lines are what people paste into a search box. The line that matters is the one naming a file and a line number.

Text
Running "npm run build"
> tallyhound@0.1.0 build
> next build

   Creating an optimized production build ...
 Compiled successfully
Failed to compile.

./app/invoices/[id]/page.tsx:18:22
Type error: Property 'totalCents' does not exist on type 'Invoice'.

Error: Command "npm run build" exited with 1

Reproduce it before you change anything

Vercel recommends building on your own machine first, because most failures are in the code or its dependencies, not in Vercel. Run a clean install and the same build command the project uses. If it fails locally with the same message, you can fix it in your editor and stop guessing.

If it passes locally, build the way Vercel does. vercel pull downloads the project settings and environment variables into .vercel/, and vercel build then runs the build locally with them. By default it uses Preview variables; add --prod to use Production ones. A failure that only appears with vercel build points at settings or variables rather than code.

Terminal
# 1. the plain build, from a clean install
rm -rf node_modules .next
npm ci
npm run build

# 2. the build with Vercel's settings and variables
npx vercel pull --yes --environment=production
npx vercel build --prod

Match the line above the exit code

What the earlier line saysLikely causeFix
Type error: ... with a file and lineNext.js fails next build on TypeScript errorsFix the type, or regenerate types after a schema change
Module not found: Can't resolve './components/usercard'Import casing differs from the file name; Vercel builds on case-sensitive LinuxMatch the casing and commit the rename
It looks like you're trying to use TypeScript but do not have the required package(s) installedNODE_ENV=production set as a project variable, so devDependencies were skippedDelete that variable or use npm install --include=dev
An error thrown while collecting page data, naming a missing key or URLCode reads a variable at build time that the environment does not haveAdd it for the environment being built, then redeploy
A complaint that a webpack configuration was foundNext.js 16 builds with Turbopack by default and refuses a custom webpack configUse next build --webpack or migrate the config
npm ci fails before the build startspackage-lock.json is out of step with package.jsonRun npm install locally and commit the lockfile

Five causes that keep coming back in AI-written apps

Coding agents write a lot of code quickly and rarely run a production build before they stop. These are the failures that follow from that habit.

When the build is cancelled rather than failed

A cancelled build is a different problem from an exit code of 1. Vercel cancels a build that runs past 45 minutes or exceeds the memory or disk of its build machine. Hobby teams always use the Basic machine with 2 vCPUs and 8 GB of memory. When a limit is reached, Vercel adds a system report to the build log, and setting VERCEL_BUILD_SYSTEM_REPORT=1 produces that report on every build. Heap out-of-memory errors in next build have their own causes and fixes, covered in a separate article.

Some failures produce no build log at all. Vercel lists an invalid vercel.json, an Ignored Build Step, a commit from someone who is not a team member, and a Marketplace integration that failed to provision. In those cases the dashboard shows an overlay with the message instead of the Building section.

Rule out the cache

A successful build updates the build cache and a failed one leaves it unchanged, so a broken cache is uncommon. When a build fails for no reason you can see, redeploy without it. In Deployments, open the menu next to the deployment, choose Redeploy and leave Use existing Build Cache unticked. From the CLI, vercel --force builds without the cache, and the variable VERCEL_FORCE_NO_BUILD_CACHE=1 skips restoring it on every build.

Confirm the fix and keep it fixed

The fix is confirmed when the deployment reaches Ready and the page that broke the build renders on the deployment URL. Then make the failure cheaper next time. Add npm run build to whatever runs before you push, for example a CI job on pull requests, so a type error stops in a branch rather than on the production deployment. Ask your coding agent to run the production build and fix every error before it reports a task as done; a line in its instructions file is enough.

Keep the variables your build needs listed in .env.example, with empty values, so a missing one is visible in review. And keep one lockfile in the repository, for the package manager the project actually uses. For a wider checklist of what agents skip before production, see the guide on going from vibe coding to production.

Where Shipyard fits

Shipyard creates the Vercel project with the framework preset and the GitHub repository attached, and writes the production and preview variables before the first build runs, which removes the missing-variable cause. It also writes a build prompt for your agent. Type errors and import casing stay in your code, so the local build above is still the quickest check.

Sources

Launch in an hour, not a weekend

Shipyard connects your accounts once, then sets up the domain, hosting, database, email and payments for every new product.

Get started See how it works

Read next