Thomas Osayi

November 17, 2026 · 9 min read · Thomas Osayi

Vercel build failed? The most common Next.js deploy errors and fixes

Why a Next.js app builds on your laptop but fails on Vercel, and how to fix type errors, missing environment variables, case-sensitive imports and more.

The app runs on your laptop. You push to GitHub, Vercel starts a deployment, and a minute later you get the email: build failed. Nothing changed between the two, except everything about how the code was run.

I fix this for founders, usually on apps started in Lovable, Bolt, v0 or Cursor. The fastest way to debug it is to run the same production build locally with npm run build. Most of the time the error appears there too, with a clearer message and no waiting. The causes are a short list, and this article goes through each one with the error text you will see.

Why does my Next.js app work locally but fail on Vercel?

Because npm run dev and a production build are different programs with different rules, and Vercel's build machine is not your laptop.

The dev server compiles one page at a time, only when you visit it, and it keeps running through type errors. The production build, next build, compiles every file, type-checks the whole project, runs lint, and prerenders every page it can. A page you never opened in development gets built on Vercel whether you remember it exists or not.

The machine differs too. Vercel builds on Linux with a clean install of your dependencies, the Node version set in the project, and only the environment variables you entered in the dashboard. Your laptop has a case-insensitive disk, months of installed packages, and a .env.local file that never left it.

Almost every failure comes from one of these:

  • TypeScript or lint errors the dev server let through
  • Environment variables that exist locally but not in Vercel
  • Imports whose letter case does not match the file name
  • Dependency, lockfile or Node version mismatches
  • Browser-only code that runs during the server build
  • Pages that fetch data at build time from something unreachable

How do I read a Vercel build log?

Open the failed deployment, expand the build logs, and find the first error, because everything after it is fallout.

The last line of a failed build is nearly always "Command npm run build exited with 1." That tells you nothing. Scroll up to the first line marked as an error, or use the search box in the log viewer and look for "Error", "Failed to compile" or "Type error".

The stage tells you the category:

  • A failure while installing dependencies points to package.json, the lockfile or the Node version
  • "Failed to compile" with a file path and line number is a type, lint or import error
  • "Collecting page data" failures are code that runs when a route file is loaded, usually an SDK set up with a missing key
  • "Generating static pages" failures are a page that crashed while being prerendered

Then reproduce it. Run npm run build locally. If it fails with the same message, you can fix and retest in seconds. If it passes locally and fails on Vercel, the difference is the environment: variables, file-name case, Node version or a package that is not listed.

How do I fix type and lint errors that only show up at build?

Fix the code the error points to, because the dev server tolerated the mistake and the build will not.

What it looks like

"Failed to compile", followed by a file path with a line and column, then "Type error: Property 'name' does not exist on type 'User'" or "Type error: 'data' is possibly 'undefined'". Lint failures look similar, with a rule name at the end such as react/no-unescaped-entities or react-hooks/rules-of-hooks.

Why AI-generated code hits this

AI tools often write a component against a data shape they assumed, then change the shape in another file. The app still runs in development, because JavaScript does not care until that exact line executes. The type checker reads every line.

The fix

Go to the line. If a value can be undefined, handle that case. If a property is missing from a type, add it to the type or stop using it. Run npx tsc --noEmit to list every type error at once without waiting for a full build, and npm run lint for the lint rules. Fix them all in one pass, or you will repeat the deploy cycle once per error.

How do I fix missing environment variables on Vercel?

Add each variable under Settings, then Environment Variables, tick the environments it applies to, and redeploy.

Your .env.local file is ignored by git on purpose, so Vercel never sees it. Until you enter the values in the dashboard, process.env.ANYTHING is undefined on the server.

What it looks like

The error rarely says "missing environment variable". You see the downstream effect: "Error: Neither apiKey nor config.authenticator provided" from Stripe, "FirebaseError: Firebase: Error (auth/invalid-api-key)", "supabaseUrl is required", or a database client complaining about an invalid connection string. These often appear during "Collecting page data", because the SDK is set up at the top of a file that the build loads.

The rules that trip people up

  • Variables apply per environment: Production, Preview and Development. A variable set only for Production is missing on preview deployments.
  • A new variable applies only to new deployments. Redeploy after adding one.
  • Variables read in the browser need the NEXT_PUBLIC_ prefix, and their values are written into the JavaScript bundle at build time.
  • Secrets such as a Stripe secret key or a service account key must never have that prefix, since anything prefixed is public.
  • Names are case-sensitive, and a stray space or quote mark pasted into the value box breaks them.
  • Multi-line values such as a Firebase private key often arrive with escaped line breaks that your code has to convert back.

Compare your local file against the dashboard line by line. Running vercel env pull with the Vercel CLI downloads what the project actually has, which makes the gap obvious.

Why do I get "Module not found" only on Vercel?

Either the import's letter case does not match the file name, or the package is not listed in package.json.

Letter case

The error reads "Module not found: Can't resolve './components/Button'". On most Macs and on Windows, an import of ./components/Button finds a file named button.tsx, because the disk ignores case. Linux does not, and Vercel builds on Linux. Make the import match the file exactly, including folder names.

Renaming has its own trap: git may not notice a change that only alters case. Rename with git mv, going through a temporary name if needed, or the old name stays in the repository and the build keeps failing.

Dependencies and Node version

If the unresolved module is a package name, it was installed on your machine but never saved to package.json, so the clean install on Vercel does not include it. Install it properly and commit both package.json and the lockfile.

Related install failures:

  • A lockfile out of sync with package.json, which pnpm reports as ERR_PNPM_OUTDATED_LOCKFILE
  • Two lockfiles in the repository, such as package-lock.json and yarn.lock, so Vercel picks a package manager you do not use
  • npm stopping with "ERESOLVE unable to resolve dependency tree" on a peer dependency conflict
  • A package that requires a newer Node version than the project is set to

Keep one lockfile, commit it, and set the Node version in the project's settings or in the engines field of package.json so it matches what you run locally.

How do I fix "window is not defined" and prerender errors?

Move browser-only code so it runs in the browser, and make sure nothing the build needs is unreachable.

Browser-only code on the server

The log says "ReferenceError: window is not defined", or document or localStorage, usually under "Error occurred prerendering page" with the route name. Next.js renders pages on the server during the build, where those objects do not exist. Using them at the top level of a file or directly in a component body breaks prerendering.

Read them inside a useEffect, which only runs in the browser, in a component marked with "use client". If a library touches window as soon as it is imported, as some chart and map libraries do, load that component with next/dynamic and server rendering turned off.

A close relative is "useSearchParams() should be wrapped in a suspense boundary at page". The fix is what it says: wrap the component that reads the search params in a Suspense boundary.

Pages that fetch during the build

If a page fetches data at build time and the API is down, slow or needs a secret that is not set, the build fails. The most common version in AI-built apps is a page that fetches its own API route at http://localhost:3000. There is no server running during a build, so the request is refused.

Call the underlying function directly from the server component instead of going through HTTP. If the page depends on the logged-in user or on live data, it should not be prerendered at all: mark it as dynamic with export const dynamic = 'force-dynamic' so it renders per request.

What should I avoid doing to force the build through?

Do not switch off the checks that are failing, because the build is telling you about a real bug before your users find it.

The tempting shortcuts are setting typescript.ignoreBuildErrors to true in next.config, disabling lint during builds, scattering @ts-ignore comments or the any type over the errors, and putting NEXT_PUBLIC_ in front of a secret so the browser can read it. AI assistants suggest all of these when asked to "make the build pass", and each one works in the narrow sense that the deploy turns green.

Then the type error that said a value might be undefined becomes a blank page for the customer whose data has that value missing. The secret with a public prefix is readable by anyone who opens the browser's developer tools. A forced deploy trades a failure you can see for one you cannot.

A worked example. A founder's deploy fails with "Type error: 'session' is possibly 'null'" in a dashboard page. Ignoring type errors deploys it. The first signed-out visitor who lands on that URL gets a crash. Handling the null case with a redirect to the login page takes two lines and fixes both the build and the bug.

When is it worth getting help, and what does it cost?

Get help when you have fixed the first error and three more appeared, or when the build passes and the live site still breaks.

One error with a clear message is a do-it-yourself job with this list. A chain of them usually means something structural: the wrong rendering mode for authenticated pages, environment handling that was never set up, or generated code that drifted out of sync with itself.

I fix single build and deploy errors as a Quick Fix from $60, typically within 2 days, with a short write-up of what was wrong and what changed. Several fixes plus a feature or integration start at $200 over about 5 days. Taking an app that is stuck all the way to a production launch starts at $600 over about 10 days. Access to the repository and the Vercel project is all I need.

The bottom line

A failed Vercel build is almost never mysterious. Run npm run build locally, read the first error in the log, and match it to the list: a type or lint error, a missing environment variable, a file-name case mismatch, a dependency or Node version problem, browser-only code on the server, or a fetch the build cannot complete. Fix the cause instead of silencing the check, and the deploy that goes green will also be the one that works.

Questions, answered in one line

Why does npm run dev work but the Vercel build fail?

The dev server is lenient; a production build type-checks and prerenders every page, which exposes errors dev mode skipped.

Why does an import work on my Mac but fail on Vercel?

macOS file systems usually ignore letter case and Vercel's Linux builders do not, so Button.tsx and button.tsx are different files there.

How do I see what failed?

Open the deployment in Vercel and read the build log from the first error, not the last line.

Do I need to redeploy after adding an environment variable in Vercel?

Yes. Environment variables apply only to new deployments, and NEXT_PUBLIC_ values are written into the bundle at build time.

Should I set ignoreBuildErrors to get the deploy through?

No. It hides TypeScript errors without fixing them, so the same bug shows up later as a runtime crash for users.

How much does it cost to have a failed Vercel build fixed?

Thomas Osayi fixes a single build or deploy error from $60, usually within 2 days, with a short write-up of what was wrong.

Sources

About the author

Thomas Osayi is a full-stack developer in Los Angeles studying computer science at Loyola Marymount University. He founded and built SQWAD, a SaaS platform Shopify brands use to run creator programs, and builds custom Next.js websites, SaaS MVPs and fixes for AI-built apps for businesses and founders.

See his work · Services and prices

Related articles

Fix, finish and launch your AI-built app

Built your app with Lovable, Bolt, v0, Replit or Cursor and got stuck? I fix the bugs, connect auth and payments, clean up the code and deploy it to production.

See the service