upgrading to ruby 2.3.0 NameError: uninitialized c

2019-07-10 19:14发布

I just upgraded Ruby 2.2.2 to 2.3.0. Whenever I run a rake task I get the following error:

Christians-Air:my_rails_app cman77$ rake --trace
rake aborted!
NameError: uninitialized constant I18n::Config::Backend
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/i18n-0.7.0/lib/i18n/config.rb:19:in `backend'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/i18n-0.7.0/lib/i18n.rb:147:in `translate'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/actionview-4.2.6/lib/action_view/helpers/translation_helper.rb:69:in `translate'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/i18n-0.7.0/lib/i18n/config.rb:19:in `backend'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/i18n-0.7.0/lib/i18n.rb:147:in `translate'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/actionview-4.2.6/lib/action_view/helpers/translation_helper.rb:69:in `translate'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/railties-4.2.6/lib/rails/engine.rb:658:in `block in run_tasks_blocks'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/railties-4.2.6/lib/rails/engine.rb:658:in `each'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/railties-4.2.6/lib/rails/engine.rb:658:in `run_tasks_blocks'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/railties-4.2.6/lib/rails/application.rb:452:in `run_tasks_blocks'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/railties-4.2.6/lib/rails/engine.rb:453:in `load_tasks'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/railties-4.2.6/lib/rails/railtie.rb:194:in `public_send'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/railties-4.2.6/lib/rails/railtie.rb:194:in `method_missing'
/Users/cman77/Dropbox/rails_projects/my_rails_app/Rakefile:9:in `<top (required)>'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/rake_module.rb:28:in `load'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/rake_module.rb:28:in `load_rakefile'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/application.rb:689:in `raw_load_rakefile'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/application.rb:94:in `block in load_rakefile'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/application.rb:93:in `load_rakefile'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/application.rb:77:in `block in run'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/lib/rake/application.rb:75:in `run'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/gems/rake-11.1.2/bin/rake:33:in `<top (required)>'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/bin/rake:23:in `load'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/bin/rake:23:in `<main>'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/bin/ruby_executable_hooks:15:in `eval'
/Users/cman77/.rvm/gems/ruby-2.3.0@jbio.3.0/bin/ruby_executable_hooks:15:in `<main>'

Anyone have experience with this? I am really stuck in terms of how to even begin to diagnose/remedy this issue.

Here is the contents of my Rakefile:

#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

ENV['NEWRELIC_ENABLE'] = 'false'

MyRailsApp::Application.load_tasks

This appears to be the offending line referenced in the I18n gem: https://github.com/svenfuchs/i18n/blob/master/lib/i18n/config.rb#L18

Update: it seems to be tied to the use of include ActionView::Helpers::TranslationHelper in one of my rake files. If I remove that line I can run rake commands.

Update2: Removing include ActionView::Helpers::TranslationHelper and replacing (t "some_text") with (I18n.t "some_text") completely resolved the issue. I will still award the bounty to anyone who can explain why this broke with a Ruby upgrade!

1条回答
男人必须洒脱
2楼-- · 2019-07-10 19:46

My guess is that you experienced that problem because you ere using the t method (an helper for controllers and views) in a rake task, instead of the standard I18n.t.

This is an uncommon and unconventional approach, so you have fallen in a possible regression that few have experienced and it has a simple solution, like the one you found: stick to the conventions.

查看更多
登录 后发表回答