-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
"ReferenceError: document is not defined" - Where? #1354
Comments
Hey, I'll move this to |
Thank you |
The actual error comes from However, you still have a few things to fix before you can prerender, as you have not wrapped you usage of |
Thank you. Question, how do you know this and I'm not? I mean there is no pointers how do I resolve. If I remember right, when I tried to build the same app with Gatsby there were notes what issues I have to fix in order to make it work |
Standard debugging procedure: take things apart from the top down. Router was basically the first stop, and your method of doing so was quite bizarre, so it was something I definitely had to check. Any reason why you're doing it that way? Once I got around that the rest of the errors showed up. Just to add, as I see you're new to Preact, it can and will offer debugging help. This is an issue with the underlying webpack plugin having issues with your code, however, so there's no much that can be returned to you. I'm not sure what entirely sets it off but that router sure isn't liked by something. |
I was just playing with Preact, I'll definitely do refactor my router back. Thank you for your help And how do I fix mini-css plugin error? Can we config Preact to skip window/document no safe dependencies on prerender? I also would like to know the way you can debug Preact. Is there any article on this one? Thank you again :) And sorry that I'm bothering you with this silly questions? It's two days since I know Preact exists |
Oh it's certainly no problem. Let me know if a minor PR could help.
The router should be altered/refactored, that should stop the main issue. Dynamically importing isn't very idiomatic and isn't saving you any complexity by any means, so while it'll take someone much smarter than myself to point out what the underlying problem actually is with the tooling, switching up your router will make it go away for sure.
If by this you mean can you tell Preact to just ignore those things, then no. That's one of the difficulties of prerendering, not everything is there during the prerender.
There's the dev tools browser extension that can help you when you can run the app, but I'm not aware of any one article in particular that might be of use. No need to apologize for asking questions, certainly a valid enough issue. I've asked my fair share of questions (and then some) around here. Happy to help more if you could use it, or feel free to ask any of the other contributors. I'm sure they'd be happy to help out too. Edit: Spoke a bit too soon, there might be some solutions out there to help with prerendering |
RomanistHere/RomanistHere.github.io@bd6183b - I fixed all the issues we've talked above, building keeps failing. How should I fix third-party issues with globals? There was solution I've found for Gatsby for example: |
I sent you a PR, figured I had it already and it better outlines what I mean. Take a look if you have a chance. Definitely don't feel the need to merge it or anything. As for globals, maybe that's where something like |
Hiya - this is almost certainly caused by the There's not much benefit in that library given that it doesn't sanitize HTML. You could remove the library entirely and replace that line with this: <div className="post__text" dangerouslySetInnerHTML={{ __html: content }} /> |
It's actually not, was related(and still is) to async routes. I can't figure a way to build async routes with pre-rendering. When I change routes to static ones, it's building just fine. I don't know what to do with it. But anyway this line of code is very useful. If it's doing the same the package does, I will remove it completely, thank you :) |
I renamed my page folder to "routes" according to documentation but started to get new error here when build with pre-rendering:
And if I use "async!" with pages folder, content in page is doubling What could be the solution? P.S. I removed reactHtmlParser completely, thank you |
Hi, I'm getting the same error during the build even if I remove all the code that is possibly can ask for a window/document - I've tried to remove all the components except main screen. The error is next:
"ReferenceError: document is not defined
at folder-with-this-project\build\ssr-build\ssr-bundle.js:1:438"
Reproduction
Here is my package: https://github.com/RomanistHere/RomanistHere.github.io/blob/preact/package.json
It's actually one from my-project example with few more dependencies - I'm trying to migrate app from React. I mean I succeeded if don't talk about pre-rendering part.
I type "npm run build"(preact build)
Steps to reproduce
it fails here: "93% (14.4s) after chunk asset optimization"
Expected Behavior
I expect to see the file with this error at least
Actual Behavior
Getting error in ssr-bundles - can't understand what I should fix
The text was updated successfully, but these errors were encountered: