-
Notifications
You must be signed in to change notification settings - Fork 10.3k
window is not defined in SSR #13057
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
Comments
What does "SSR" actually mean? Please don't use acronyms and assume that everyone immediately knows exactly what you mean.
The code in that file is not intended to run outside of a browser-context, hence it's not clear why changes are necessary here!? |
Server side rendering |
Thanks for the clarification; but as mentioned that file isn't really intended to be used in such a situation. Edit: Please note that the pre-processor statement looks the way it does to avoid a useless Line 741 in 709c57a
|
I don't know why but the error exists and there are issues about it even in this repository: @wojtekmaj Can you join to conversation? |
I got the same problem. |
@timvandermeij What's your opinion here, should we make the small change outlined in #13057 (comment) or close this as wontfix given the specialized use-case? |
If the small change is the only thing necessary to make this work for those frameworks (it's not entirely clear if it is from this issue, so we'll need a verification for that), I think it would be fine to do that. |
Another way to fix it would be to simply write const animationStarted = new Promise(function (resolve) {
if (typeof window === "undefined" || typeof window.requestAnimationFrame !== "function")) {
setTimeout(resolve, 20);
} else {
window.requestAnimationFrame(resolve);
}
}); |
That's not really an acceptable solution though, since as a general rule we don't want to add useless runtime checks in Firefox; please note #13057 (comment). |
@wojtekmaj A few questions here, so that we have a complete picture to evaluate possible solutions:
[1] Although, as mentioned previously, all files in that folder are written with the assumption that they're run in a browser context. |
I think the issue here was that I needed PdfLinkService to get links working in PDFs, and PDFLinkService required EventBus, which, when imported, evaluated the entire ui_utils.js unfortunately, because ui_utils isn't side effect free. I created our own custom link service now in React-PDPF 5.3.0 beta so that should no longer be an issue - at least from our side, unless someone else will try the same thing. |
While using pdfjs in frameworks with SSR like Next.js or Gatsby there is an error while build phase
ReferenceError: window is not defined
The error occurs at line 563 in
ui_utils.js
Looks like all changes needs is:
There is an issue in react-pdf: wojtekmaj/react-pdf#657
The text was updated successfully, but these errors were encountered: