Repository: gatsbyjs/gatsby

Issue #25298: 'window is not defined' error from build files
Created: 2020-06-25T14:20:15Z
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:
failed Building static HTML for pages - 3.497s

 ERROR #95312 

"window" is not available during server side rendering.

See our docs page for more info on this error: https://gatsby.dev/debug-html





  WebpackError: ReferenceError: window is not defined
  
  - build-html.js:107 doBuildPages
    [zeitouni]/[gatsby]/dist/commands/build-html.js:107:24
  
  - build-html.js:121 async buildHTML
    [zeitouni]/[gatsby]/dist/commands/build-html.js:121:3
  
  - build.js:219 async build
    [zeitouni]/[gatsby]/dist/commands/build.js:219:5


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

Duplicate issue #25304: 'window is not defined' error from build files (used correctly everywhere)
Created: 2020-06-25T16:16:46Z
Description
I don't use window anywhere in my code without checking if it's defined first.
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:
failed Building static HTML for pages - 3.497s

 ERROR #95312 

"window" is not available during server side rendering.

See our docs page for more info on this error: https://gatsby.dev/debug-html





  WebpackError: ReferenceError: window is not defined
  
  - build-html.js:107 doBuildPages
    [zeitouni]/[gatsby]/dist/commands/build-html.js:107:24
  
  - build-html.js:121 async buildHTML
    [zeitouni]/[gatsby]/dist/commands/build-html.js:121:3
  
  - build.js:219 async build
    [zeitouni]/[gatsby]/dist/commands/build.js:219:5


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

Closing comment (2020-06-25T18:00:06Z): This looks like duplicate of #25298, and given that the newer one already have some discussion going, I'll close this one