The real root cause of CI build failures was NOT Turbopack, but
Resend initialization at module level without API key.
Problem:
- Resend was initialized at module level: const resend = new Resend(process.env.RESEND_API_KEY)
- During build, Next.js collects page data and imports all modules
- If RESEND_API_KEY is not set, Resend throws error: 'Missing API key'
- This caused build to fail with 'Failed to collect page data for /api/contact'
Solution:
- Implement lazy initialization pattern for Resend
- Only initialize Resend when actually needed (when sending emails)
- Add proper error handling if API key is missing
Changes:
- src/app/api/contact/route.ts: Add getResend() function with lazy init
- src/app/(marketing)/contact/actions.ts: Add getResend() function with lazy init
This allows the build to succeed even without RESEND_API_KEY in CI,
while still requiring it at runtime when actually sending emails.
- Move CI/CD configs to config/ci/ directory
- Reorganize scripts into categorized directories (deployment, monitoring, testing, utils)
- Consolidate documentation into docs/ directory with proper structure
- Update linting and testing configurations
- Remove obsolete test reports and performance summaries
- Add new documentation for code quality tools and contact form security
- Improve project organization and maintainability
- Fix lint-staged config to only lint JS/TS files
- Disable react/react-in-jsx-scope rule for Next.js compatibility
- Ignore scripts and test config directories in ESLint
- Create public config API for frontend consumption
- Add configuration fetching to homepage
- Implement module show/hide logic based on config
- Add support for Services items filtering
- Add support for Products featured products and pricing display
- Add support for News display count, categories, and sort order
- Fix table name from 'configs' to 'siteConfig' in API route
- Update type definitions for proper TypeScript support
- Remove server-side grouping logic from API response
- Return flat array instead of grouped object
- Fix data structure mismatch between API and frontend
- Resolve TypeError when accessing admin settings page