If you reference “document” in a Gatsby site, it will fail on build.
E.g.:
Error:
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.
E.g.:
if (!document) { return ; }