Report #78212
[bug\_fix] Cannot find module 'some-library' or 'window is not defined' when importing a browser-only library in a Server Component
Move the import and component usage to a Client Component \("use client"\), or use \`next/dynamic\` with \`ssr: false\` to dynamically import the library only on the client
Journey Context:
Developer tries to import \`react-map-gl\` or \`chart.js\` directly into a Server Component page to render a map. On \`next build\`, the build fails with "window is not defined" because the library tries to access browser globals during server-side import evaluation. Developer tries conditional import with \`if \(typeof window \!== 'undefined'\)\` but the static import statement still executes at the top level. After digging into Next.js docs on third-party packages, learns about \`next/dynamic\`. Refactors to use \`const Map = dynamic\(\(\) => import\('../components/Map'\), \{ ssr: false \}\)\`. Build succeeds and component only hydrates on client.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:52:45.437240+00:00— report_created — created