Vercel build failed with "npm run build" exited with 1: how to fix it
The app runs fine on your machine or in the builder's preview, but every Vercel deploy fails with Error: Command "npm run build" exited with 1. That line is only the summary. The real reason is a few lines above it, and it's nearly always one of the problems below.
1. Find the real error
Open the failed deployment in Vercel and click Build Logs. Scroll up from the exited with 1 line to the first red error. Copy that line; it tells you which of the sections below you need. You can reproduce the same build on your own computer with:
npm ci
npm run build
npm ci installs exactly what's in your lockfile, like Vercel does, so it catches problems a plain npm install hides.
2. TypeScript errors
Dev servers often show type errors as warnings and keep running. A production build stops on them. Look for lines like Type error: or error TS2322 with a file name and line number. Fix the type, or for a quick unblock make the value's type explicit. Avoid turning type checking off for the whole project; it hides real bugs.
3. Lint errors (Next.js)
Next.js runs ESLint during next build, and some rules are errors, such as unused variables or react-hooks rules. The log shows Failed to compile followed by the rule name. Fix the listed lines. As a last resort while you fix them, Next.js lets you skip lint during builds with eslint: { ignoreDuringBuilds: true } in next.config.
4. "Module not found" that works on your Mac or Windows PC
Vercel builds on Linux, where file names are case-sensitive. An import of ./components/Navbar works locally if the file is navbar.tsx, but fails on Vercel with Module not found: Can't resolve. Make the import match the file name exactly. If you renamed only the case of a file, Git may not have noticed; rename it with git mv navbar.tsx Navbar.tsx and push.
5. Missing environment variables at build time
Values in your local .env file aren't uploaded. If code reads a variable while building (Vite's VITE_ variables, Next.js NEXT_PUBLIC_ variables, or anything used in static pages), the build can crash with errors like supabaseUrl is required. Add every variable in Settings, Environment Variables for the Production environment, then redeploy. Our guide to env variables undefined on Vercel goes through this in detail.
6. Dependency and lockfile problems
ERESOLVE unable to resolve dependency tree: two packages want different versions of the same thing (often React). Update the older package. If you must, set the install command tonpm install --legacy-peer-depsin the project's build settings.- Two lockfiles: a
package-lock.jsonnext to abun.lockb,pnpm-lock.yamloryarn.lockconfuses the install. Keep the one for the package manager you really use and delete the others. - Lockfile out of date:
npm cifails ifpackage.jsonand the lockfile disagree. Runnpm installlocally and commit the updated lockfile.
7. Node.js version
If the log mentions an unsupported engine or syntax errors inside node_modules, your project needs a different Node version than Vercel is using. Set it under Settings, Build and Deployment, Node.js Version, or add an engines field to package.json, such as "engines": { "node": "22.x" }.
8. Out of memory
Large apps can fail with JavaScript heap out of memory or a build that stops with no clear error. Remove unused heavy dependencies first. Vercel's docs on troubleshooting builds cover memory limits and other build errors.
Quick checklist
- Read the first red error above
exited with 1 npm ci && npm run buildpasses on your machine- Imports match file names exactly, including capital letters
- All environment variables added in Vercel for Production
- One lockfile, committed and up to date
- Node.js version set to what the project needs
Still stuck?
Mendlark fixes this kind of problem for a fixed €49 (launch price, normally €79). We agree the problem first, test the fix and send it as a pull request, so nothing changes in your app until you merge it. If we can't fix it, you don't pay. Get the €49 fix, or start with a free scan.
Not sure what else is wrong? Paste your app link into the free instant check and get a plain-English list of problems in seconds.