Installed a charting package, imported it in my dashboard page, and the build fails with ReferenceError: window is not defined. The component already has "use client" at the top. I thought that meant it runs in the browser?
It runs in the browser as well. A Client Component is still rendered once on the server to produce the first HTML, and only then hydrated in the browser. Any library that touches window when it is imported blows up during that server pass.
Two fixes, depending on where the browser-only code is.
Your own code uses window: move it into useEffect, which only runs in the browser.
A library uses it on import: load it only on the client with next/dynamic: