SolidStart SSR "window is not defined" in CI
During SSR there is no DOM, so window, document, and localStorage are undefined. If a component touches them at module load or render time, the server build or prerender step throws window is not defined.
What this error means
The build or a prerender step fails with "ReferenceError: window is not defined" (or document/localStorage), pointing into a component that reads a browser global outside a client-only path.
ReferenceError: window is not defined
at Component (/build/server/chunk.mjs:12:19)
at renderToStringAsync (@solidjs/web)Common causes
A browser global read during SSR
Accessing window/document at the top level or in the render body runs it on the server where those globals do not exist.
A browser-only library imported eagerly
A package that touches the DOM on import is pulled into the server bundle and fails at render.
How to fix it
Guard browser code with isServer / onMount
- Move DOM access into
onMount, which only runs on the client. - Or branch on
isServerfromsolid-js/webbefore touching a browser global. - Load browser-only libraries lazily inside those client paths.
import { onMount } from 'solid-js';
import { isServer } from 'solid-js/web';
onMount(() => {
const w = window.innerWidth; // runs only in the browser
});
if (!isServer) { /* browser-only work */ }Use clientOnly for a whole component
Wrap a component that cannot render on the server so SolidStart skips it during SSR.
import { clientOnly } from '@solidjs/start';
const Chart = clientOnly(() => import('./Chart'));How to prevent it
- Access browser globals only inside
onMountor!isServerbranches. - Wrap browser-only components with
clientOnly. - Avoid importing DOM-touching libraries at module top level.