-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
window is not defined #287
Comments
do you use server-side rendering? |
do you use server-side rendering? |
I started having the same issue with this library. I use Gatsby and can confirm it no longer works with SSR. |
Hi, I was having the same issue with NextJS, I tried to check the source code but I didn't find anything weird so I find a solution for this. What I did was dynamic importing with no SSR So, instead of the traditional importing:
This works for me, have a nice day. |
I have a workaround #292 |
I have the same issue (using Gatsby) and your workaround works for me. Thanks! |
It seems it works for me. |
Hey @piotr-s-brainhub, for me, this workaround unfortunately does not work. I use NextJS 9.2.3 with SSR. |
But SSR with |
Okay, for some reason it works now. However, the component ignores the width of the outer element :-/ Is there any solution? |
do you encounter the same problem without SSR or only with SSR? |
@nescha @Neddz @Sorvereign @jannispaul @semy does this example https://github.com/brainhubeu/react-carousel/pull/301/files work for you? |
For those using Gatsby, here's a horrible & gross hack to work around this issue: // gatsby-node.js
module.exports.onPreInit = () => {
const carouselSrcFile =
'node_modules/@brainhubeu/react-carousel/lib/react-carousel.js';
if (!fs.existsSync(carouselSrcFile)) return;
fs.writeFileSync(
carouselSrcFile,
fs
.readFileSync(carouselSrcFile, 'utf8')
.replace('(window,', `(typeof window==='undefined'?{}:window,`)
);
}; |
@cadejscroggins Does this hack really work? |
@piotr-s-brainhub it works. When rendered in a browser, |
@cadejscroggins so does the |
@piotr-s-brainhub it does. Including it in future releases would be very helpful. |
See possible fix via webpack config to reinstate webpack 3 behaviour on #344. |
If you use Dots and have problem with
|
Was having this issue only when deploying to Netlify, everything ran fine on my local Gatsby dev server. @piotr-s-brainhub Your patch worked great! Thanks for the fix. EDIT: I spoke too soon, now for some reason the plugins aren't working? Specifically the slidesToShowPlugin and arrowsPlugin. LATEST EDIT: Rather than using the older version/patch, Gatsby has a solution for these kinds of SSR errors using this package and using it to import the component (in this case, the carousel component):
This finally solved the issue for me! |
How did you make the plugins work (slidesToShowPlugin, autoplayPlugin, etc ...) ? |
An error happens during build after recent update to @brainhubeu/react-carousel@1.12.6:
ReferenceError: window is not defined at Object.<anonymous> ([ROOT]/react/node_modules/ brainhubeu/react-carousel/lib/react-carousel.js:1:279
The text was updated successfully, but these errors were encountered: