rails / jbuilder

Jbuilder: generate JSON objects with a Builder-style DSL
MIT License
4.34k stars 440 forks source link

JBuilder 2.11.3: uninitialized constant ActionView::AbstractRenderer on load under Nginx/Passsenger #518

Closed scott-bergen-talogy closed 2 years ago

scott-bergen-talogy commented 3 years ago

App environment:

Debugging the app in Rubymine works fine but on our servers, the app won't start with the error below. Have not had a chance to troubleshoot yet but it is happening at the Bundler.require step of loading application.rb

App 21999 output: Error: The application encountered the following error: uninitialized constant ActionView::AbstractRenderer App 21999 output: Did you mean? AbstractController (NameError) App 21999 output: /data/var/www/assessments/releases/assessments_20211106142834/vendor/bundle/ruby/3.0.0/gems/actionview-6.1.4.1/lib/action_view/renderer/partial_renderer.rb:254:in <module:ActionView>' App 21999 output: /data/var/www/assessments/releases/assessments_20211106142834/vendor/bundle/ruby/3.0.0/gems/actionview-6.1.4.1/lib/action_view/renderer/partial_renderer.rb:5:in<top (required)>' App 21999 output: /data/var/www/assessments/releases/assessments_20211106142834/vendor/bundle/ruby/3.0.0/gems/actionview-6.1.4.1/lib/action_view/renderer/collection_renderer.rb:3:in <top (required)>' App 21999 output: /data/var/www/assessments/releases/assessments_20211106142834/vendor/bundle/ruby/3.0.0/gems/jbuilder-2.11.3/lib/jbuilder/collection_renderer.rb:5:in<top (required)>' App 21999 output: /data/var/www/assessments/releases/assessments_20211106142834/vendor/bundle/ruby/3.0.0/gems/jbuilder-2.11.3/lib/jbuilder/jbuilder_template.rb:2:in <top (required)>' App 21999 output: /data/var/www/assessments/releases/assessments_20211106142834/vendor/bundle/ruby/3.0.0/gems/jbuilder-2.11.3/lib/jbuilder/railtie.rb:2:in<top (required)>' App 21999 output: /data/var/www/assessments/releases/assessments_20211106142834/vendor/bundle/ruby/3.0.0/gems/jbuilder-2.11.3/lib/jbuilder.rb:365:in <top (required)>' App 21999 output: /usr/local/rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/runtime.rb:66:inrequire' App 21999 output: /usr/local/rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/runtime.rb:66:in block (2 levels) in require' App 21999 output: /usr/local/rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/runtime.rb:61:ineach' App 21999 output: /usr/local/rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/runtime.rb:61:in block in require' App 21999 output: /usr/local/rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/runtime.rb:50:ineach' App 21999 output: /usr/local/rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/runtime.rb:50:in require' App 21999 output: /usr/local/rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler.rb:174:inrequire' App 21999 output: /data/var/www/assessments/releases/assessments_20211106142834/config/application.rb:7:in <top (required)>' App 21999 output: /data/var/www/assessments/releases/assessments_20211106142834/config/environment.rb:2:inrequire' App 21999 output: /data/var/www/assessments/releases/assessments_20211106142834/config/environment.rb:2:in <top (required)>' App 21999 output: config.ru:3:inrequire' App 21999 output: config.ru:3:in block in <main>' App 21999 output: /data/var/www/assessments/releases/assessments_20211106142834/vendor/bundle/ruby/3.0.0/gems/rack-2.2.3/lib/rack/builder.rb:125:ininstance_eval' App 21999 output: /data/var/www/assessments/releases/assessments_20211106142834/vendor/bundle/ruby/3.0.0/gems/rack-2.2.3/lib/rack/builder.rb:125:in initialize' App 21999 output: config.ru:1:innew' App 21999 output: config.ru:1:in <main>' App 21999 output: /usr/local/rvm/gems/ruby-3.0.2/gems/passenger-enterprise-server-6.0.12/src/helper-scripts/rack-preloader.rb:85:ineval' App 21999 output: /usr/local/rvm/gems/ruby-3.0.2/gems/passenger-enterprise-server-6.0.12/src/helper-scripts/rack-preloader.rb:85:in preload_app' App 21999 output: /usr/local/rvm/gems/ruby-3.0.2/gems/passenger-enterprise-server-6.0.12/src/helper-scripts/rack-preloader.rb:173:inblock in ' App 21999 output: /usr/local/rvm/gems/ruby-3.0.2/gems/passenger-enterprise-server-6.0.12/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:437:in run_block_and_record_step_progress' App 21999 output: /usr/local/rvm/gems/ruby-3.0.2/gems/passenger-enterprise-server-6.0.12/src/helper-scripts/rack-preloader.rb:172:in' App 21999 output: /usr/local/rvm/gems/ruby-3.0.2/gems/passenger-enterprise-server-6.0.12/src/helper-scripts/rack-preloader.rb:14:in <module:PhusionPassenger>' App 21999 output: /usr/local/rvm/gems/ruby-3.0.2/gems/passenger-enterprise-server-6.0.12/src/helper-scripts/rack-preloader.rb:13:in

'

TigerWolf commented 3 years ago

I can confirm that I have this issue too. In my specs I get this error:

Failure/Error: require File.expand_path("../config/environment", __dir__)

NameError:
  uninitialized constant ActionView::AbstractRenderer
# ./config/application.rb:9:in `<main>'
# ./config/environment.rb:3:in `<main>'
# ./spec/rails_helper.rb:6:in `<main>'
# ./spec/services/sso_spec.rb:3:in `<main>'
# ------------------
# --- Caused by: ---
# LoadError:
#   cannot load such file -- action_view/renderer/collection_renderer
#   ./config/application.rb:9:in `<main>'
jrochkind commented 2 years ago

I don't believe it's related to nginx/passenger, I'm getting it without.

I thought it was related to Rails 7, I started getting it when I tried running my tests under Rails 7. But you report Rails 6.1.

But the ActionView::AbstractRenderer still exists even in Rails 7...

Aha, I bet it's a zeitwerk loading issue. I bet those having the problem are using zeitwerk; which was optional before Rails 7, but mandatory in Rails 7.

The class is ActionView::AbstractRenderer, but it's located at path action_view/renderer/abstract_renderer.rb -- the extra /renderer in there may be making zeitwerk fail to load it where it did before.

I would like to try to file a ticket in Rails, but I can't figure out how to make a simple reproduction. :( I

am pretty sure this is zeitwerk related though.

rafaelfranca commented 2 years ago

Zeitwerk doesn't load the framework code, so this has nothing to do with Zeitwerk. The issue was caused by https://github.com/rails/jbuilder/commit/d84c37d8981e5165275ecd4884c56ab34cd4a65e. I'm fixing.