Fix guides · Cursor, v0, Lovable ·

Fix Next.js "Build failed because of TypeScript errors"

Type error: ... Build failed because of TypeScript errors (next build / vercel deploy)

`next build` type-checks your whole project and refuses to finish if TypeScript finds any error. `next dev` does not block on type errors, so the app can work locally and still fail on Vercel. The fix is to run the production build locally, read the exact file and line in the `Type error:` message, and correct the code (types, null checks, props, import paths) instead of switching type checking off.

Free · 3 a day · no signup

Common causes – and how to tell which one you have

1. Type errors the dev server didn't block

How to tell: The log shows `Type error:` with a file path and line number, often things like `Object is possibly 'undefined'`, `Property 'x' does not exist on type`, or a missing required prop. The page works fine in `npm run dev`.

Fix: Open the file and line from the log and fix the real problem: add a null check, pass the missing prop, or correct the type. Run `npx tsc --noEmit` to list every type error at once, then fix them all before redeploying.

2. Leftover files that nothing imports

How to tell: The error points to a file you never open in the browser, such as an old component, a test, a script, or a duplicate like `page-old.tsx`. The dev server only compiles files a page actually uses. The build checks every file matched by `include` in `tsconfig.json`.

Fix: Delete files you no longer need, or fix them. If a folder truly isn't part of the app (for example a scripts folder), add it to `exclude` in `tsconfig.json`.

3. Page props typed for an older Next.js version

How to tell: The error mentions `PageProps`, `LayoutProps`, `params` or `searchParams`, often saying a type 'does not satisfy the constraint'. This usually happens when AI-generated code types `params` as a plain object on Next.js 15 or later.

Fix: In Next.js 15+, `params` and `searchParams` are Promises. Type them as `Promise<{ slug: string }>` and `await` them inside the component (or use `use()` in a client component). Check your Next.js version in `package.json` first.

4. Import path capitalisation doesn't match the file

How to tell: You see `Cannot find module './components/Button'` or a message that a file name 'differs only in casing', even though the file exists on your machine. macOS and Windows ignore letter case in file names by default, but Vercel's Linux build servers don't.

Fix: Make the import match the real file name exactly. If you renamed a file by changing only its casing, Git may not have recorded the change. Use `git mv button.tsx Button.tsx` (via a temporary name if needed) and commit.

5. Different package versions on Vercel

How to tell: The error mentions types from a library or from `node_modules`, or appeared after a dependency update. The build passes locally but fails on Vercel, and your lockfile (`package-lock.json`, `pnpm-lock.yaml`, etc.) is missing from the repo or out of date.

Fix: Commit an up-to-date lockfile so Vercel installs the same versions you have. Locally, run a clean install (for example `npm ci`) and `npm run build` to reproduce Vercel's result, then update your code for the library's current types.

6. Possibly-undefined env vars or stale generated types

How to tell: The error says `Type 'string | undefined' is not assignable to type 'string'` on a `process.env.X` line. Or it involves database types, such as a Supabase table or column that 'does not exist' in a generated `types.ts`.

Fix: For env vars, check that the value exists and throw a clear error if it doesn't, so TypeScript knows it's a string afterwards. For database types, regenerate them from your current schema (for example with the Supabase CLI's type generation) and commit the updated file.

How to fix it

  1. Copy the full error from the Vercel build log, including the file path and line number after `Type error:`.
  2. Run `npm run build` locally (after `npm ci` for a clean install) and confirm you get the same error.
  3. Run `npx tsc --noEmit` to see every type error at once, since `next build` stops at the first one.
  4. Fix each error in the code: add null checks, pass missing props, correct types, and update `params`/`searchParams` to Promises if you're on Next.js 15+.
  5. Delete or fix unused leftover files, and make every import path match the real file name's capitalisation.
  6. Commit your lockfile and any regenerated types, then run `npm run build` again until it finishes without errors.
  7. Push and confirm the Vercel deployment goes green.

Using Lovable, Bolt or v0?

In Vercel, open the failed deployment, find the build logs, and copy the full `Type error:` block, including the file path and line number. Paste it into Lovable or v0 and ask it to fix that exact error without disabling TypeScript checks or adding `@ts-ignore`, then redeploy. If the error mentions database tables or columns, ask the tool to regenerate the Supabase types from your current schema, since a table changed in the Supabase dashboard won't update the types file by itself.

Using Cursor, Claude Code or Windsurf?

Ask the agent to run `npx tsc --noEmit` and `npm run build` itself, fix every reported error at its source, and re-run the build until it exits cleanly. Tell it explicitly not to touch `ignoreBuildErrors`, `strict`, or add `@ts-ignore`/`as any`. After it finishes, review the diff for new `any` types or deleted code paths, and for a final check run a clean install (`npm ci`) followed by `npm run build`.

The “fix” to avoid

Agents often set `typescript: { ignoreBuildErrors: true }` in `next.config`, turn off `strict`, or sprinkle `@ts-ignore` and `as any` until the build passes. The Next.js docs call ignoring build errors dangerous: the deploy succeeds, but the real bug (an undefined value, a missing prop, a wrong param shape) ships to production and crashes there instead. Fix the types so the compiler keeps protecting you.

Copy-paste fix prompt for your AI coding tool

Paste this into Cursor, Claude Code, Lovable or Bolt:

My deploy fails during `next build` with "Type error: ... Build failed because of TypeScript errors", though `npm run dev` works. Run `npx tsc --noEmit` and `npm run build` to see every error. Check, in order: (1) real type errors such as possibly-undefined values, missing props, or wrong types; (2) unused leftover files included by tsconfig; (3) page/layout `params` or `searchParams` not typed as Promises on Next.js 15+; (4) import paths whose capitalisation differs from the actual file name; (5) `process.env` values used as plain strings; (6) stale generated database types. Fix each at its source. Do not set `ignoreBuildErrors`, disable `strict`, or add `@ts-ignore`/`as any`. Then run `npm ci` and `npm run build` and repeat until the build completes with zero errors. Summarise what you changed.
Your error looks a bit different? Paste your exact error and get a diagnosis tailored to your code — free.

Questions people ask

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

`next dev` doesn't block on TypeScript errors, but `next build` type-checks the whole project and stops if it finds one. Vercel also builds on Linux, which treats `Button.tsx` and `button.tsx` as different files. Running `npm run build` locally reproduces the failure.

Is it safe to set ignoreBuildErrors to true?

Only as a short, deliberate stopgap. The Next.js docs warn it's dangerous because type errors then ship to production unchecked. Fixing the reported errors is almost always faster than debugging the runtime crashes they cause.

How do I see all the TypeScript errors at once?

Run `npx tsc --noEmit` in the project folder. It checks every file your `tsconfig.json` includes and lists all errors without building, while `next build` stops at the first one.

Official documentation

Related errors

Get fixes like this every week