Back to Troubleshooting
Troubleshooting

Build failures

8 min

Common Build Failures

Build failures are frustrating, but usually easy to fix. Here are the most common causes and solutions.

Missing Dependencies

Symptom

Error: Cannot find module 'some-package'

Solution

Make sure the package is listed in package.json dependencies:

npm install some-package --save

Build Command Failed

Symptom

Command failed with exit code 1

Solution

  1. Check your build logs for specific error messages
  2. Verify your build command in project settings
  3. Test the build locally: npm run build
  4. Ensure all required environment variables are set

Out of Memory

Symptom

FATAL ERROR: Reached heap limit

Solution

Increase Node.js memory limit:

// package.json
"scripts": {
  "build": "NODE_OPTIONS='--max-old-space-size=4096' next build"
}

TypeScript Errors

Symptom

TS2307: Cannot find module or its type declarations

Solution

  1. Install missing type definitions: npm install --save-dev @types/package-name
  2. Check tsconfig.json configuration
  3. Ensure TypeScript version compatibility

Environment Variable Issues

Symptom

Undefined environment variable

Solution

  • Add missing variables in project settings
  • Remember: client-side variables need special prefixes (NEXT_PUBLIC_, VITE_, etc.)
  • Redeploy after adding variables

Debugging Build Failures

  1. Read the logs: The full error message usually contains the answer
  2. Test locally: Run the same build command on your machine
  3. Check recent changes: What changed since the last successful build?
  4. Clear cache: Sometimes a clean build fixes issues

Getting Help

If you're still stuck:

  • Share your build logs with support
  • Check the community forum for similar issues
  • Try deploying a minimal reproduction

Was this article helpful?

Need more help?

Our support team is available 24/7 to assist you.

Contact Support