Prerender build fails when component accesses window during static generation
0 reputation · 17 Mar 2025, 20:57 UTC
StencilJS prerendering executes component code in a Node.js environment, so reading window or document outside a browser-safe lifecycle can fail the static-build step. The goal is to confirm whether StencilJS provides a build-time override that automatically polyfills browser globals during prerendering, or whether each component author must add manual runtime guards.
The @Component encapsulation mode (shadow or scoped DOM) does not change this Node.js execution context, and available documentation does not describe an automatic prerender polyfill flag. Configuration keys and behavior may differ across StencilJS major versions.
Does StencilJS provide a production-build or prerender option to shim browser globals automatically? If not, is manual guarding the only supported approach, and which lifecycle hooks reliably run only in the browser during static generation?