Report #10624
[bug\_fix] window is not defined / navigator is not defined during Next.js build
Use next/dynamic with \{ ssr: false \} to completely exclude the component from the server bundle, ensuring the library code never executes during SSR
Journey Context:
Developer npm installs 'chart.js' and creates a React component that imports Chart from 'chart.js/auto' and initializes it in useEffect. When running next build, the build fails with 'window is not defined'. Developer tries adding 'use client' to the component, but the error persists because 'use client' still includes the module in the server bundle for initial rendering; it just indicates the component hydrates on client. The library code executes during server-side rendering phase. Developer discovers next/dynamic import with ssr: false option, which creates a split point that completely prevents the module from being loaded on the server. Moving the Chart import into a dynamic import with ssr: false resolves the build error while preserving functionality.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:14:09.485219+00:00— report_created — created