Skip to content
Latchkey

Next.js ESLint errors failing next build in CI

next build runs ESLint over your app and any lint error (not just a warning) fails the build with "Failed to compile". This is why a build can break on a rule violation that the dev server ignored.

What this error means

next build prints "Failed to compile." followed by ESLint output such as "Error: 'x' is defined but never used no-unused-vars" or a next/core-web-vitals rule, ending the job non-zero.

next build
Failed to compile.

./app/page.tsx
12:9  Error: 'data' is assigned a value but never used.  @typescript-eslint/no-unused-vars

info  - Need to disable some ESLint rules? Learn more here:
https://nextjs.org/docs/app/api-reference/config/eslint

Common causes

ESLint reports an error-level rule during the build

Next runs lint as part of next build; any rule set to "error" fails compilation, unlike warnings which do not.

CI lints files that local runs skipped

A clean checkout lints the whole project, so a violation in a file you did not touch locally now fails.

How to fix it

Fix the reported lint errors

  1. Run npx next lint to reproduce the exact errors CI sees.
  2. Resolve each error, or apply autofixes with npx next lint --fix.
  3. Re-run next build to confirm lint passes.
Terminal
npx next lint
npx next lint --fix

Adjust rule severity deliberately

If a rule should not block builds, downgrade it to a warning in ESLint config rather than disabling lint entirely.

eslint.config.mjs
// eslint.config.mjs
rules: { '@typescript-eslint/no-unused-vars': 'warn' }

How to prevent it

  • Run next lint in CI as a separate step so failures are clear.
  • Keep rule severities intentional rather than ignoring all lint.
  • Avoid eslint.ignoreDuringBuilds unless lint runs elsewhere.

Frequently asked questions

What causes "ESLint errors fail next build"?
Next runs lint as part of next build; any rule set to "error" fails compilation, unlike warnings which do not.
How do I fix ESLint errors fail next build?
Fix the reported lint errors

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card