react-router-sitemap
react-router-sitemap copied to clipboard
How should we deal with window ?
My routes are using components as follow:
<Route exact path={getUserUrl(":userId")} component={withTracker(User)} />
And some of the components use the window object. We installed the window-or-global package, then I changed the entry point of my webpack config to start at script/sitemap-builder.js
instead of src/app.js
, but when trying to run node dist/sitemap-builder.js
, I'm still getting a ReferenceError: window is not defined
.
Our project is written in es6 with a bunch of other webpack stuff (like loading css files), and since we import all the major components in our routes.js
file, we cannot escape seeing a window or css import when running the sitemap builder script, so using node or babel-node as-is is a no-go. Using node on the generated output from webpack is triggering the window issue, so I'm a bit lost here.
Did you already experience this issue ? Any tip on how to resolve it ?
@Fandekasp how do you use window-or-global? You are replace window keyword to root from this package?
@Fandekasp did you find a way to solve the window problem, because I am also getting this same error for my project and could you help me with what changes are required to work this with webpack, regarding entry points setup and where should I keep this so that it runs always at the time of deployment.
window-or-global is equivalent to if(typeof window !== 'undefined')
and allows you to avoid using window when you are on node side.