Build failed with 1 error
Module not found: Can't resolve './components/Header'
Type error: Property 'x' does not exist on type 'Y'
Your JavaScript build (Vite, Webpack, Next.js, Astro) failed. Here are the most common causes.
Fix 1: Module Not Found
# ❌ Importing a file that doesn't exist
import Header from './components/Header'; # 💥 Wrong path
# ✅ Check the actual file path and extension
ls src/components/Header.*
# Common issues:
# - Case sensitivity: Header vs header (Linux is case-sensitive)
# - Missing extension: ./utils vs ./utils.ts
# - Wrong relative path: ../ vs ./
Fix 2: TypeScript Type Error
# ❌ Build fails on type errors
# ✅ Fix the type error, or temporarily skip type checking
# Next.js — skip type checking in build
# next.config.js
module.exports = {
typescript: { ignoreBuildErrors: true }, // Temporary!
};
# Vite — type checking is separate
npx tsc --noEmit # Check types without building
Fix 3: Out of Memory During Build
# ❌ Large project runs out of memory
FATAL ERROR: JavaScript heap out of memory
# ✅ Increase Node memory
NODE_OPTIONS="--max-old-space-size=4096" npm run build
Fix 4: Dependency Issue
# ❌ Package version conflict
# ✅ Clean install
rm -rf node_modules package-lock.json .next dist
npm install
npm run build
Fix 5: Environment Variable Missing
# ❌ Build expects env vars that aren't set
# ✅ Check your .env file exists
# Vite: must prefix with VITE_
# Next.js: must prefix with NEXT_PUBLIC_ for client-side
# Or provide at build time
VITE_API_URL=https://api.example.com npm run build
Fix 6: Syntax Error in Config
# ❌ Invalid config file
# ✅ Validate your config
node -e "require('./vite.config.js')"
node -e "require('./next.config.js')"
# Common issues:
# - Trailing commas in JSON
# - Missing module.exports
# - ESM vs CommonJS mismatch
Debugging
# Build with verbose output
npm run build -- --debug
# Check for circular dependencies
npx madge --circular src/
# Clear all caches
rm -rf node_modules/.cache .next/cache dist