Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Vercel says npm run build exited with 1 and my deployment fails

ErrorError: Command "npm run build" exited with 1

Short answer

Exited with 1 only says the build script failed. The cause is a few lines above it in the build log. Reproduce it locally with the same command first. If it passes locally, check the Output Directory, the Root Directory and whether the build was killed for memory.

  • Applies to Node.js 22, npm 10, Vercel
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run the exact build command on your machine from a clean install. Vercel's own guide recommends this before anything else, because it shows the error without the log noise.

    rm -rf node_modules
    npm ci
    npm run build
  2. 2Match what you see, then jump to its fix

    1. 1A red Error line earlier in the build log; the final exited with 1 line is only a summaryThe build fails for a reason that shows above the last lineFix
    2. 2Build finishes, then Vercel reports the output directory is missing, empty or invalidThe Output Directory does not match what the build producedFix
    3. 3The repo has a front-end subfolder, and the log shows no package.json or a different app being builtThe Root Directory points at the wrong folderFix
    4. 4The log ends abruptly or mentions a system report for memory or diskThe build container ran out of memory or diskFix

What does the error look like?

  • Error: Command "npm run build" exited with 1
  • Error: Command "yarn run build" exited with 1

Cause 1 of 4

The build fails for a reason that shows above the last line

1Check

Scroll up from the last log line. The useful message is usually a few lines above it, and the local build normally prints the same one.

npm run build 2>&1 | tail -n 40

2Fix

Fix the error it names (a type error, an import that does not resolve, a missing package), then commit and push.

npm run build
git add -A && git commit -m "Fix build error" && git push

3Verify

The local build ends cleanly, and the new deployment reaches Ready.

echo $?

Confirmed by vercel.com

Did this fix it?

Cause 2 of 4

The Output Directory does not match what the build produced

1Check

The build step errors when the output directory is missing, empty or not a directory. Compare the folder your build writes with the Output Directory in project settings.

npm run build
ls dist build out 2>/dev/null

2Fix

Set the Output Directory to the folder the build really writes, or switch the Framework Preset back to the correct one.

{
  "outputDirectory": "dist"
}

3Verify

Redeploy and check that the build log ends with a completed deployment.

vercel deploy

Confirmed by vercel.com

Did this fix it?

Cause 3 of 4

The Root Directory points at the wrong folder

1Check

In a repository where the app lives in a subfolder, Vercel builds from the Root Directory set in project settings. A wrong value builds the wrong thing.

ls; ls frontend

2Fix

Set Root Directory under Settings, Build and Deployment to the folder that holds the app's package.json.

# Dashboard: Project Settings > Build and Deployment > Root Directory > frontend > Save

3Verify

Redeploy; the log's install step should now list that app's dependencies.

vercel deploy

Confirmed by vercel.com

Did this fix it?

Cause 4 of 4

The build container ran out of memory or disk

1Check

Builds that exceed the memory or disk of the build machine are cancelled. Setting VERCEL_BUILD_SYSTEM_REPORT=1 as an environment variable prints a report on every deployment.

# Add VERCEL_BUILD_SYSTEM_REPORT=1 in Project Settings > Environment Variables, then redeploy

2Fix

Import less in the build (large icon sets, media, third-party SDKs), or use a larger build machine type.

# Dashboard: Project Settings > Build and Deployment > build machine

3Verify

The next build completes and the report shows memory below the limit.

# Dashboard: open the new deployment and read the Building section of its logs

Confirmed by vercel.com

Did this fix it?

How do I stop it coming back?

  • Run npm ci and npm run build before every push to a production branch.
  • Keep the lockfile committed so Vercel installs the same tree as your machine.
  • Check build logs on preview deployments, not only production.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.