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' failed build process #25411
Comments
(I updated the desc to add the code in a code block, only. It was already a partial paste). The example you pasted was cut off. Do you have a repo with a reproduction we can take a look at? In general it should be safe to do |
Hello Peter. Thank you for your answer. Yes I've got a repository with the whole project (a simple and personal project) but I'm not sure I want to make it public and accessible. As I said above, the code I pasted is the one that make the build fail. I implemented a switch button in a header which enable the user to toggle between two languages (english and french). I would like the user choice to be stored in local storage so that when the page refreshes the user choice is kept in memory. For instance if the user switches to french and refreshes the page, french will be still displayed and not english by default. But honestly after one day of headaches about this trying many things, I'm on the point of giving up and removing this feature. Maybe it is not that relevant... |
Try putting undefined in a string like "undefined". It's what works for me! |
That seems like a reasonable bug to resolve. Going to close this. If that did not resolve it please reopen and report a new repro. |
Hello. I got the 'Window is not defined' error during the build process using Netlify. I know this is a recurrent issue and I checkout a lot of documentation on how to solve this but unfortunately I was unable to figure it out. Consider I'm still in the React learning process.
For instance I checked this:
https://www.gatsbyjs.org/docs/debugging-html-builds/#how-to-check-if-window-is-defined
#309
What I try to do:
I implemented a switch button on a single webpage which enable the user to toggle between two languages. The user language preference is supposed to be stored in local storage. I thought about using a useEffect hook to solve the problem but as a beginner I'm still confused about how to use it.
Thank you by advance for you help.
Code:
Below is the code that encounter the problem during build process:
The text was updated successfully, but these errors were encountered: