Skip to content
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

Error with Rails 5 in production env #403

Closed
renchap opened this issue Nov 13, 2015 · 12 comments
Closed

Error with Rails 5 in production env #403

renchap opened this issue Nov 13, 2015 · 12 comments

Comments

@renchap
Copy link

renchap commented Nov 13, 2015

Rails 5 : rails/rails@472b8e0
react-rails : 290765a
Sprockets : rails/sprockets@c8b96cd

When deploying in the production env, I get this error :

NoMethodError: undefined method `[]' for nil:NilClass
File ".../bundle/ruby/2.2/bundler/gems/react-rails-290765a1ac14/lib/react/server_rendering/sprockets_renderer.rb" line 14 in block in initialize
File ".../bundle/ruby/2.2/bundler/gems/react-rails-290765a1ac14/lib/react/server_rendering/sprockets_renderer.rb" line 13 in each
File ".../bundle/ruby/2.2/bundler/gems/react-rails-290765a1ac14/lib/react/server_rendering/sprockets_renderer.rb" line 13 in initialize
File ".../bundle/ruby/2.2/bundler/gems/react-rails-290765a1ac14/lib/react/server_rendering.rb" line 22 in new
File ".../bundle/ruby/2.2/bundler/gems/react-rails-290765a1ac14/lib/react/server_rendering.rb" line 22 in create_renderer
File ".../bundle/ruby/2.2/bundler/gems/react-rails-290765a1ac14/lib/react/server_rendering.rb" line 12 in block in reset_pool

The error occurs here :

js_code << ::Rails.application.assets[filename].to_s

After looking in the console, Rails.application.assets is empty in this environment. Setting config.assets.compile = true in config/environments/production.rb fixes the issue.

I dont really know how this can be fixed otherwise, this is my first try at react / react-rails.

@SylarRuby
Copy link

Are you using ruby 2.2.1+?

@renchap
Copy link
Author

renchap commented Nov 13, 2015

Yes, ruby 2.2.3p173

@SylarRuby
Copy link

Maybe a bug in react-rails. Others will comment.

@rmosolgo
Copy link
Member

I think it's the same problem as #288, but now it totally 💥s instead of just being inefficient.

Sorry I haven't gotten a chance to fix it yet! Maybe this afternoon.

@acconrad
Copy link

Any progress on this? I'm seeing this issue on Rails 4.2.5 with Ruby 2.1.5 and Sprockets 3.5.2 (Sprockets-rails 3.0)

@losvedir
Copy link

This 💥 s for us when precompiling assets, even though we aren't using prerender: true anywhere. One solution if you don't need the server side rendering is to just configure a dummy renderer:

config.react.server_renderer = Class.new do
  def initialize(params = {})
  end

  def render(component_name, props, prerender_options)
    ''
  end
end

Can @rmosolgo comment if this would have any negative consequences I'm not thinking of if we're not using server side rendering?

@rmosolgo
Copy link
Member

If you're not using server-side rendering, I can't imagine any negative consequences! That's a nice application of the null object pattern :)

Sorry I've been kicking the can on this, just installed the new Rails 5 beta to reproduce the issue locally!

@rmosolgo
Copy link
Member

I reproduced the issue locally and "fixed" it with this patch: #430

Still a few things to do there but at least I can see the way forward :D

@losvedir
Copy link

Thanks!

@augnustin
Copy link

Any quick workaround for new comers?

@rmosolgo
Copy link
Member

rmosolgo commented Feb 8, 2016

You could try: #443 (comment)

@rmosolgo
Copy link
Member

rmosolgo commented Dec 9, 2016

I guess this is fixed on recent versions, please let me know if it isn't!!

@rmosolgo rmosolgo closed this as completed Dec 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants