Report #29628
[bug\_fix] Cannot read properties of undefined \(reading 'map'\) when importing a library that depends on window in a Server Component
Use \`next/dynamic\` with the \`ssr: false\` option to force the component to only render on the client, ensuring the library is never loaded during server rendering.
Journey Context:
Developer installs a visualization library like \`recharts\` or \`chart.js\` and imports it directly into a page file in the Next.js App Router. Upon running \`next dev\`, the app crashes immediately with \`ReferenceError: window is not defined\` originating deep inside the library's code. The developer understands that Server Components cannot access browser globals, but the library is a black box. They search for 'Next.js chart library window error' and find community examples showing \`next/dynamic\`. They refactor their import from a static import to \`const Chart = dynamic\(\(\) => import\('../components/MyChart'\), \{ ssr: false \}\)\`. This ensures the component \(and its heavy library dependency\) are only required and rendered in the browser, completely bypassing the server render phase where \`window\` is missing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T04:07:07.623037+00:00— report_created — created