build-start
Build & Start
Quick Start
When building or starting the application:
- Development:
npm run devornpm run dev:turbo - Production Build:
npm run build - Production Start:
npm run start - Vercel Build:
npm run build:vercel
Commands
Development Server
# Standard development server
npm run dev
# Development with Turbopack (faster)
npm run dev:turbo
Port: 3000 (default)
Features: Hot reload, error overlay, fast refresh
Production Build
# Standard production build
npm run build
# Vercel-optimized build
npm run build:vercel
Output: .next directory
Time: Typically 20-60 seconds
Verification: Check for build errors and warnings
Production Server
# Start production server
npm run start
Port: 3000 (default)
Environment: Requires NODE_ENV=production
Deploy y caché (Vercel)
Después del deploy, para que los assets y el HTML se actualicen rápido en todos los dispositivos:
# Purgar CDN + Data Cache (requiere Vercel CLI y vercel login)
npm run cache:purge
- Panel Vercel: Settings → Caches → Purge CDN Cache + Purge Data Cache.
- Assets: Las URLs de tenant llevan
?v=<commit-sha>(cache busting);/imagesy/tenantstienen caché 24h. Verdocs/CACHE_PURGE_ANTES_DEPLOY.md. - Flujo recomendado: deploy → luego
npm run cache:purge(o purgar desde el panel).
Build Process
Pre-build Steps
The build process includes automatic pre-build steps:
- React Cache Polyfill:
scripts/create-react-cache-polyfill.js- Creates polyfill for
react/cachecompatibility - Required for Next.js 16 compatibility
- Creates polyfill for
Build Configuration
Key build settings in next.config.js:
- TypeScript: Build errors ignored (temporary)
- Compiler: Console removal in production
- Output: Optimized for Vercel deployment
- Bundle Analyzer: Enabled with
ANALYZE=true - Cache busting:
NEXT_PUBLIC_ASSETS_VERSION(desdeVERCEL_GIT_COMMIT_SHAen Vercel) para que las URLs de assets de tenant cambien en cada deploy
Common Build Issues
TypeScript Errors
If TypeScript errors block the build:
# Check TypeScript errors
npx tsc --noEmit
# Build ignores TypeScript errors (configured in next.config.js)
npm run build
Memory Issues
If build fails due to memory:
# Increase Node memory limit
NODE_OPTIONS="--max-old-space-size=4096" npm run build
Module Resolution Errors
If you see module resolution errors:
- Clear
.nextdirectory:rm -rf .next - Clear node_modules:
rm -rf node_modules && npm install - Rebuild:
npm run build
Verification Checklist
After building:
- Build completes without errors
- No critical warnings in console
-
.nextdirectory created successfully - Production server starts correctly
- Pages load without runtime errors
- Environment variables loaded correctly
Environment Variables
Required for production build:
NEXT_PUBLIC_*variables (exposed to client)- Database connection strings
- API keys and secrets
- Tenant configuration
Check .env.local.example for required variables.
Performance Targets
- Build Time: < 20s (target)
- First Load JS: < 500KB
- Bundle Size: Optimized with code splitting
Troubleshooting
Build Fails with React Cache Error
# Ensure polyfill script runs
node scripts/create-react-cache-polyfill.js
npm run build
Build Succeeds but Runtime Errors
- Check browser console for errors
- Verify environment variables are set
- Check server logs for API errors
- Verify database connections
Slow Build Times
- Use Turbopack:
npm run dev:turbo - Check for large dependencies
- Review bundle analyzer output
- Consider incremental builds
Key Files
next.config.js- Build configuration (incl. env NEXT_PUBLIC_ASSETS_VERSION)package.json- Build scripts (cache:purgepara purgar caché Vercel)scripts/create-react-cache-polyfill.js- Pre-build scriptdocs/CACHE_PURGE_ANTES_DEPLOY.md- Guía purga de caché y actualización de assets.env.local- Environment variables
More from santiagoxor/pintureria-digital
postgres-best-practices
Postgres performance optimization guidelines from Supabase. Contains rules across 8 categories prioritized by impact. Use when writing SQL queries, designing schemas, implementing indexes, optimizing queries, reviewing database performance, configuring connection pooling, or working with Row-Level Security (RLS).
29testing-qa
Specialized skill for writing and maintaining tests including unit tests, integration tests, E2E tests with Playwright, and accessibility tests. Use when writing tests for new features, debugging failed tests, improving test coverage, or setting up E2E tests.
18error-handling
Specialized skill for implementing proper error handling, logging, user-friendly error messages, and error recovery strategies. Use when implementing error handling in APIs, components, or when debugging error issues.
17supabase-mcp-db
Apply Supabase migrations and manage the database using the Supabase MCP (user-supabase-SantiagoXOR). Use when the user asks to apply migrations, run migrations with MCP, manage the DB with Supabase MCP, list migrations, execute SQL, or inspect schema.
15multitenant-development
Specialized skill for working with the multitenant system including tenant detection, data isolation, tenant-specific configuration, and RLS policies. Use when implementing multitenant features, creating APIs that handle multiple tenants, configuring tenant assets, or debugging data isolation issues.
15supabase-database
Specialized skill for working with Supabase PostgreSQL database including queries, RLS policies, migrations, functions, and data operations. Use when implementing database queries, creating migrations, setting up RLS policies, writing SQL functions, or debugging database issues.
13