Vercel deployment fails with "npm run build" exit code 1 error
I was trying to deploy my next js app on Vercel, but facing this error repeatedly :
Error: Command "npm run build" exited with 1What should I look into to resolve this ?
PS: I tried overriding the build command with
CI= npm run build… got the same error
Command "npm run build" exited with 1 only tells you the build failed. The cause is printed earlier in the build log. Find the first real error there, fix it, and redeploy. Overriding the build command with CI= npm run build doesn't change the underlying failure.
1. Read the full build log
In Vercel, open the failed deployment and look at Build Logs. A deployment clones the repo, installs dependencies, builds the site, then deploys (deploy guide). Find the step that failed and the first error above the "exited with 1" line. Typical causes are a TypeScript or lint error, a Module not found import (often a wrong path or filename casing), or code that throws during prerendering because a value is missing.
2. Reproduce it locally
npm run buildIf the local build fails too, fix it there first. If it passes locally but fails on Vercel, the difference is usually the environment (see the next step) or files that are on your machine but not committed.
3. Check environment variables
.env.local shouldn't be committed to Git, so Vercel doesn't have those values. You need to add them again when you deploy (what sanity init generates). In the Vercel project's Environment Variables, add every entry from your local .env.local, for example:
NEXT_PUBLIC_SANITY_PROJECT_ID="your-project-id"
NEXT_PUBLIC_SANITY_DATASET="production"If your code reads a token, add it under the exact name your code uses. Sanity's Vercel integration can inject these for you. It sets NEXT_PUBLIC_SANITY_PROJECT_ID, NEXT_PUBLIC_SANITY_DATASET (and SANITY_/SANITY_STUDIO_ variants), plus the server-side secrets SANITY_API_READ_TOKEN and SANITY_API_WRITE_TOKEN. Check that these names match what your code expects.
4. Remove --turbopack from the build script
Sanity's deploy guide flags this deploy error: if your package.json build script uses --turbopack, remove it. The guide calls this likely a temporary issue.
{
"scripts": {
"build": "next build"
}
}5. After it deploys
If the Studio is embedded at /studio, open it on the deployed URL. You'll be prompted to add that URL as a CORS origin, which every URL that reads Sanity content client-side needs (deploy guide).
If you're still stuck, copy the first error from the build log. That error points to the file or setting to fix.
Show original thread3 replies
Was this answer helpful?
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.