Fix errors · Skill
Fix Next.js build errors
fix-nextjs-build-errors
Fixes a Next.js build that fails on next build or in a Vercel deploy - read the first real error, then work through type errors, server-only code in client components, missing env vars at build time, bad imports and prerender failures. Use when next build fails, a Vercel build log is red, or the app runs in dev but will not build.
Works with: Any AI Not yet model-tested; testing Jan 2027
Paste it into ChatGPT, Claude, Gemini or any AI chat, then tell it about your project. How it works
Install in Claude Code, Cursor or Codex (optional)
Only for AI coding tools that read skill folders. Run one line in a terminal, in your project folder. It downloads this skill's text files from TheSkillVault and nothing else; you can read them first with “View raw SKILL.md”.
Claude Code (all your projects)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/fix-nextjs-build-errors/raw' -o ~/'.claude/skills/fix-nextjs-build-errors/SKILL.md'Cursor (this project)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/fix-nextjs-build-errors/raw' -o '.cursor/skills/fix-nextjs-build-errors/SKILL.md'Codex and other Agent Skills tools (this project)
curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/fix-nextjs-build-errors/raw' -o '.agents/skills/fix-nextjs-build-errors/SKILL.md'
Or connect the whole library over MCP
Add TheSkillVault to Cursor or add this to your app's MCP settings (read-only; help):
{
"mcpServers": {
"theskillvault": {
"url": "https://theskillvault.ai/mcp"
}
}
}next dev is forgiving and next build is strict. Most build failures fall into a handful of patterns.
When to use
npm run buildfails locally or the Vercel deploy log shows "Build failed".- The app works in development but not once built.
- You see "Error occurred prerendering page" or "Module not found".
When not to use
- The build passes but the page breaks in the browser with a hydration warning. Use fix-react-hydration-errors.
Steps
- Run
npm run buildlocally so you can repeat the error quickly. - Scroll up to the first error, not the last line. Later errors are often side effects.
- Type errors: fix the reported file and line. Do not set
ignoreBuildErrorsto hide them. - "Module not found": check the path case (Linux is case-sensitive), the import alias in
tsconfig.json, and that the package is independencies. - "You're importing a component that needs useState": add
"use client"to that component, or move the hook into a small client component. - Server-only code (database,
fs, secret keys) imported by a client component: move it to a server component, a route handler or a server action. - Prerender errors: the page calls an API or env var at build time. Add a fallback, make the page dynamic, or set the env var in the build environment.
- Missing env vars: make sure the host has them for the build step, and that browser values start with
NEXT_PUBLIC_. - Clear
.nextand reinstall withrm -rf .next node_modules && npm ciif errors make no sense. - Rebuild, then deploy again and confirm the build log is green.
Gotchas
- Never move a secret into a
NEXT_PUBLIC_variable to fix a build. It will ship to every browser. - Lockfile out of sync with
package.jsonmakes CI install different versions. Commit the lockfile. - A different Node version on the host can break builds. Pin it in
package.jsonengines or the host settings. - Disabling ESLint or TypeScript in the build hides real bugs until users find them.
Portability
Works for Next.js 13-15 with the App Router or Pages Router. If you deploy on Netlify, Cloudflare or a Docker host instead of Vercel, the same errors show in that build log.
Example prompt
"My Next.js app works with npm run dev but Vercel says Build failed. Here is the log. Find the cause and fix it."
Done when
npm run buildpasses locally with no ignored errors.- The hosted deploy builds green.
- The cause is written in the commit message.
---
House original by TheSkillVault (CC-BY-4.0).
Licence
Licence: CC BY 4.0. Attribution when you reuse it: From TheSkillVault, https://theskillvault.ai, CC BY 4.0