Replies: 1 comment 4 replies
-
This doesn't really have much to do with node.js or esm. What's happening is that during a production build, each page is built using "server-side rendering". In that context, window, for example, doesn't exist. All code and packages that rely on browser specific APIs (for example web APIs) should be conditionally excluded. Most implementation do something like: if (typeof window !== 'undefined') {
// ... require, use code that needs window to exist
} Note that this is not specific to react-static but is a limitation on all SSR solutions unless window is mocked-in (as a no-op polyfill). |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was amaized how quickly I could move all of my pure React code into React-Static and it worked as expected. Great stuff.
But then I tried building it and I keep bumping into this.
How would you say that I escape this node.js execution of browser code? I tried adding return statements if window or document is undefined, but without any results. I read everything I could find on react-static, but I'm probably lacking knowledge of node.js to fix this properly.
Please let me know if some specific info is needed. Here's my package.json
Beta Was this translation helpful? Give feedback.
All reactions