-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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' error from build files #25298
Comments
In several of your components, you reference Issue #309 references this same problem. To fix it, check if window is defined like this: if typeof window !== 'undefined' {
// This will only run in the browser where window is defined, so add your event listeners here
} Hope this helps! |
I was doing some checks here, and there are few problems here: |
Tried the workaround suggested in the gatsby docs you sent. Put the snippet in error:
|
Ah, the
Now - given that the components you use here wraps other content - I would suggest something like this:
and then import Other options is always trying different 3rd party components - there might SSR friendly one which would let you avoid doing those workarounds. |
@EliasJorgensen just as @pieh mentioned the major problem was that the |
@femioladeji Cheers for pinging me, but i think you've got the wrong guy 😄 |
Ooops I meant @EliranGooner 🤦♂️ |
Description
In build I constantly get the dreaded 'window is not defined' error from files I'm sure how to tackle. These are files I suspect have to do something with the page build and they consistently throw this error only in build time.
I major change I did today is re-installing the
package-lock.json
file to solve another issue. But this came up after the initial issue was solved.Repo: https://github.com/EliranGooner/zeitouni
Steps to reproduce
Run
gatsby build
Expected result
No
window
related issues as I don't use it un-safely in my code, knowing it might cause problems with SSR.Actual result
The error:
Environment
System:
OS: macOS 10.15.4
CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.18.1 - ~/.nvm/versions/node/v12.18.1/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.5 - ~/.nvm/versions/node/v12.18.1/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 83.0.4103.116
Safari: 13.1
npmPackages:
gatsby: ^2.19.7 => 2.23.11
gatsby-background-image: ^0.10.2 => 0.10.2
gatsby-cli: ^2.10.9 => 2.12.51
gatsby-image: ^2.2.39 => 2.4.9
gatsby-plugin-env-variables: ^1.0.1 => 1.0.2
gatsby-plugin-google-analytics: ^2.2.2 => 2.3.6
gatsby-plugin-google-fonts: ^1.0.1 => 1.0.1
gatsby-plugin-manifest: ^2.2.39 => 2.4.14
gatsby-plugin-offline: ^3.0.32 => 3.2.13
gatsby-plugin-prefetch-google-fonts: ^1.4.3 => 1.4.3
gatsby-plugin-react-helmet: ^3.1.21 => 3.3.6
gatsby-plugin-robots-txt: ^1.5.0 => 1.5.1
gatsby-plugin-sass: ^2.1.30 => 2.3.6
gatsby-plugin-sharp: ^2.4.3 => 2.6.14
gatsby-plugin-sitemap: ^2.3.1 => 2.4.7
gatsby-plugin-transition-link: ^1.18.0 => 1.20.2
gatsby-source-filesystem: ^2.1.46 => 2.3.14
gatsby-transformer-sharp: ^2.3.13 => 2.5.7
The text was updated successfully, but these errors were encountered: