react-router-sitemap icon indicating copy to clipboard operation
react-router-sitemap copied to clipboard

How should we deal with window ?

Open AdrienLemaire opened this issue 6 years ago • 3 comments

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 ?

AdrienLemaire avatar Mar 29 '18 08:03 AdrienLemaire

@Fandekasp how do you use window-or-global? You are replace window keyword to root from this package?

kuflash avatar Mar 29 '18 10:03 kuflash

@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.

adityatandon007 avatar Mar 28 '19 09:03 adityatandon007

window-or-global is equivalent to if(typeof window !== 'undefined') and allows you to avoid using window when you are on node side.

Yvanovitch avatar Oct 08 '19 02:10 Yvanovitch