Understanding Next.js Static Exports
Next.js provides a powerful way to generate fully static websites. By setting output: 'export' in your next.config.js (or enforcing it with export const dynamic = 'error'), you guarantee that all pages are pre-rendered at build time.
Why Static Exports?
- Performance: Static HTML files load instantly.
- Security: No database or server logic is exposed at runtime.
- Hosting: Can be deployed anywhere (Cloudflare Pages, GitHub Pages, Vercel, S3).
Example Configuration
Here is how you might configure a statically exported page:
// app/page.tsx
export const dynamic = 'error';
export default function Home() {
return <h1>Hello, Static World!</h1>;
}
Notice the dynamic = 'error' setting. If any component in the tree attempts to read request-time data (like search params or cookies), the build will fail immediately instead of falling back to dynamic rendering. This is crucial for maintaining performance guarantees.

