title: Gatsby window not available during server side rendering build error
body: <p>I am trying to build my Gatsby site to deploy to production, but I have run into an issue which I believe is related to one line of code within my application where I use <code>window</code> to redirect to an external url that is retrieve from a GET request made on a button click. I tried to read through the <a href="https://www.gatsbyjs.com/docs/debugging-html-builds/" rel="noreferrer">documentation on this issue</a> and attempted to use their window check conditional, but my redirect either didn't work or I received an error related to <code>Can't resolve 'module'</code>. Is there an alternative route to either replacing the use of <code>window</code> all together or fixing why this runs during build and causing the error?</p>
  <p>Error:</p>
  <pre><code>failed Building static HTML for pages - 2.611s
  
   ERROR #95312
  
  &quot;window&quot; is not available during server side rendering.
  </code></pre>
  <p>Error for code checking for window:</p>
  <pre><code>  WebpackError: ReferenceError: window is not defined
  </code></pre>
  <p>Code:</p>
  <pre><code>authClick(e) {
          e.preventDefault();
          this.setState({ authorizing: true }, ()=&gt; {
              axios.get(auth_url)
                  .then((res) =&gt; {
                      this.setState({
                          authorizing: false
                      })
  
                      window.location.replace(res.data) // Window call
  
                      // Attempt to fix the issue based on documentation
                      // if (typeof window !== `undefined`){ 
                      //     const module = require(&quot;module&quot;)
                      //     window.location.replace(res.data) 
                      // }
                  }).catch((err) =&gt; {
                      console.log(err)
                  })
          });
      }
  
  // Component
      &lt;button className=&quot;inline-flex items-center&quot; onClick={this.authClick} disabled={this.state.authorizing}&gt;
      Auth
      &lt;/button&gt;
  </code></pre>