-
Notifications
You must be signed in to change notification settings - Fork 754
ReferenceError: document is not defined #319
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
Thanks for posting a thorough example! Do you encounter this problem only when I ask because the ExecJS context used for prerendering has no access to I don't see a reference to |
Thank you for the prompt response, |
I'm getting the same exact issue. I'm trying to make server rendering work with https://github.com/justin808/react-webpack-rails-tutorial/ |
for what it's worth i did: var document = typeof document === 'undefined' ? '' : document; in code that i reference |
@rmosolgo I've tried the test project posted by @TheRusskiy and it turns out that the problem is caused by this line in react_ujs.js.erb. Removing the dependency on However, I was wondering if there would be a better solution to this? Perhaps we could remove the reference to
|
I have code in react_on_rails that simply checks if document is defined before doing anything that's client based (as opposed to server rendering based). Thus, have a conditional before any place you'd need to use document on the server rendering part. |
I'm server rendering quite a few pages using browserify to bundle my js. I had not run into this issue. However, when trying to move to a build process using webpack I started hitting this. In my component code (not sure about library code) I don't have anywhere that is referencing It seems strange that the code produced by my browserify build would work, but the same code transpiled with webpack isn't. Does anyone have any suggestions for further debugging? |
@aflanagan if you want a webpack based solution, take a look at https://github.com/shakacode/react_on_rails/ and the example app: https://github.com/shakacode/react-webpack-rails-tutorial/. |
@justin808 i've definitely looked at that a few times. :) If this was a new or new-ish project I'd definitely give it a shot, but we're working on a pretty big production app that is slowly being ported to react. We have a setup we're pretty happy with, would just like to solve this one issue with moving to webpack... |
Hello guys, I am getting "ReferenceError: document is not defined"
when trying to render my component.
I don't usually create issues but I am starting to pound my head against a wall.
Set up is pretty simple so I can't wrap my head around what went wrong here.
I pushed my test project to Github: https://github.com/TheRusskiy/befluent
Main files:
application.rb: https://github.com/TheRusskiy/befluent/blob/master/config/application.rb
javascripts: https://github.com/TheRusskiy/befluent/tree/master/app/assets/javascripts
view: https://github.com/TheRusskiy/befluent/blob/master/app/views/welcome/index.html.erb
I see that there's another "document is not defined" issue created, but I don't think a guy there has the same problem.
I would really appreciate a new set of eyes on this problem.
Thank you so much in advance!
The text was updated successfully, but these errors were encountered: