-
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
WebpackError with no indication of where it happens (stacktrace) #25507
Comments
WebpackError: ReferenceError: document is not defined
Again, with no indication of where it happens.WebpackError: ReferenceError: document is not defined
with no indication of where it happens.
WebpackError: ReferenceError: document is not defined
with no indication of where it happens.
To fix this, find the offending code and either 1)check before calling the code if window is defined so the code doesn’t run while Gatsby is building (see code sample below) or and you can visit:https://www.gatsbyjs.org/docs/debugging-html-builds/ for more info |
Hi @escavalier thank you.
As you can see from my post there is no indication where my code fails. Moreover there is no reference to document anywhere in my code. The error message mentions a build.js and a build-hrml.js files but I guess they are build files, not under my control. And of course I checked https://www.gatsbyjs.org/docs/debugging-html-builds/ Any other suggestion? |
We fixed error message (particularly stack trace and location) in #25385 which was released in |
Hi @pieh actually yes I have a slightly older version:
Updating now and I will post about results. |
@pieh , changed to
But now i get new errors that i don't know how to handle, such as
But I didn't change anything :/ Help! |
Please create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it. |
I guess the main "Bug" is the lack of information being given after the error. Just so that we're on the same page, is this not a normal thing? I mean, does the build usually fail with a better explanation as to why? |
I figured out my issue: |
Hi @Jacob124! I'm glad that you managed to find the error! However, as we can't do much to help about the errors not being show without a reproduction, I'll have to close this issue :( If you are able to create a minimal reproduction for this then please do reopen the issue. If you want to share your real project, you can also send it to me directly to Thanks! |
FIXED... see all to the end OK, so now I also run into same problem and looks like will have to rebuild the project from point zero step by step to trace what is causing this problem as there is no indication where it comes from ;) My Gatsby version is 2.22.15 failed Building static HTML for pages - 6.883s ERROR #95312 "document" is not available during server side rendering. See our docs page for more info on this error: https://gatsby.dev/debug-html WebpackError: ReferenceError: document is not defined
UPDATE After updating Gatsby to 2.24.7 I now can see what is causing the error and that is That is funny, because initially I did have variable name document that had data from graphql query, but changed it to mdx after adding mdx, and forgot to rename variable, at the same time Gatsby didn't raise any error during develop as Gatsby interpreted document as global variable related to html page, and only during build process after updating to latest version it noticed that something was not correct here :) |
Please use a version equal to or later than 2.23.12 as pointed out here: #25507 (comment) |
@LekoArts Thanks, I got it fixed, but it's a kind of funny how I did build a ground for this problem initially |
Summary
I get
WebpackError: ReferenceError: document is not defined
when trying tonpm run build
on a Gatsby site that works fine indevelop
.But there's no indication as to where it happens.
I looked at many other similar cases online, but they all show where the code is failing. Here, nothing. I also checked the files one by one, there isn't any
document
in any of the js files in/
or in/src/
. I'm lost!Relevant information
and here is the log file content
Environment (if relevant)
File contents (if changed)
gatsby-config.js
:package.json
: N/Agatsby-node.js
:gatsby-browser.js
: N/Agatsby-ssr.js
: N/AThe text was updated successfully, but these errors were encountered: