Vercel says npm run build exited with 1 and my deployment fails
Error: Command "npm run build" exited with 1Short 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.
Fix it fast
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 build2Match what you see, then jump to its fix
- 1
A 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
Build finishes, then Vercel reports the output directory is missing, empty or invalidThe Output Directory does not match what the build producedFix - 3
The 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
The log ends abruptly or mentions a system report for memory or diskThe build container ran out of memory or diskFix
- 1
What does the error look like?
Error: Command "npm run build" exited with 1Error: 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 402Fix
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 push3Verify
The local build ends cleanly, and the new deployment reaches Ready.
echo $?Confirmed by vercel.com
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/null2Fix
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 deployConfirmed by vercel.com
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 frontend2Fix
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 > Save3Verify
Redeploy; the log's install step should now list that app's dependencies.
vercel deployConfirmed by vercel.com
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 redeploy2Fix
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 machine3Verify
The next build completes and the report shows memory below the limit.
# Dashboard: open the new deployment and read the Building section of its logsConfirmed by vercel.com
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
npm install fails with ERESOLVE during my Vercel deployment
npm ERR! ERESOLVE unable to resolve dependency tree
ERESOLVE means two packages ask for incompatible peer dependency versions and npm refuses to guess.
3 causes, each with a fixWeb 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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fix