yaodingyd / react-flickity-component

A React.js component for using @desandro's Flickity
314 stars 51 forks source link

[V4] ReferenceError: window is not defined #139

Closed alexw23 closed 1 year ago

alexw23 commented 1 year ago

Recently upgraded to the latest version of this package, along side NextJS V13/React V18 etc.

And now getting the following error:

error - ReferenceError: window is not defined
    at /private/tmp/react-flickity-component-example/node_modules/react-flickity-component/dist/react-flickity-component.umd.js:2:47057
    at /private/tmp/react-flickity-component-example/node_modules/react-flickity-component/dist/react-flickity-component.umd.js:2:47088
    at /private/tmp/react-flickity-component-example/node_modules/react-flickity-component/dist/react-flickity-component.umd.js:1:75
    at Object.<anonymous> (/private/tmp/react-flickity-component-example/node_modules/react-flickity-component/dist/react-flickity-component.umd.js:1:279)
....

I found other issues https://github.com/yaodingyd/react-flickity-component/issues/4#issuecomment-486740187 that attempt to solve this issue using the following:

const Flickity =
  typeof window !== "undefined"
    ? require("react-flickity-component")
    : () => null

However prior to upgrading to V4 we hadn't had this issue.

I've created a clean instance of the react-flickity-component-example, bringing it up to speed with the latest versions and was able to replicate the issue. See the window-error-demo branch.

Any idea how we can overcome this issue whilst keeping this component in SSR for performance reasons?

yaodingyd commented 1 year ago

Are you sure this branch has your change? the latest commit is still on 11/16/2020.

alexw23 commented 1 year ago

Code is up now, there was an error pushing which I didn't realise.

yaodingyd commented 1 year ago

can you try v4.0.1?

alexw23 commented 1 year ago

That's working now, thanks for the fix!