Gatsby define global document variable

If you reference “document” in a Gatsby site, it will fail on build.




  WebpackError: TypeError: Cannot read property 'documentElement' of undefined

To fix this, you need to return quickly, so that the code doesn’t get to the unused reference in the mind of the compiler.


        if (!document) { return 
; }

Leave a Reply

Your email address will not be published. Required fields are marked *