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

Fatal error when deploying production: LoadError: cannot load such file -- rubocop/rake_task #4

Closed
kaydanzie opened this issue Aug 25, 2017 · 7 comments
Labels

Comments

@kaydanzie
Copy link

kaydanzie commented Aug 25, 2017

When trying to run cap production deploy for PR #3 I got an error on the step deploy:assets:precompile. It's trying to run rake test when it shouldn't.

Error:

01 /usr/local/rbenv/bin/rbenv exec bundle exec rake assets:precompile
      01 rake aborted!
      01 LoadError: cannot load such file -- rubocop/rake_task
      01 /var/www/imposter/releases/20170825174722/lib/tasks/test.rake:1:in `require'
      01 /var/www/imposter/releases/20170825174722/lib/tasks/test.rake:1:in `<top (required)>'
      01 /var/www/imposter/shared/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/engine.rb:648:in `load'
      01 /var/www/imposter/shared/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/engine.rb:648:in `block in r…
      01 /var/www/imposter/shared/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/engine.rb:648:in `each'
      01 /var/www/imposter/shared/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/engine.rb:648:in `run_tasks_…
      01 /var/www/imposter/shared/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/application.rb:440:in `run_t…
      01 /var/www/imposter/shared/bundle/ruby/2.4.0/gems/railties-5.1.3/lib/rails/engine.rb:457:in `load_tasks'
      01 /var/www/imposter/releases/20170825174722/Rakefile:6:in `<top (required)>'
      01 /var/www/imposter/shared/bundle/ruby/2.4.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
      01 /usr/local/rbenv/versions/2.4.0/bin/bundle:22:in `load'
      01 /usr/local/rbenv/versions/2.4.0/bin/bundle:22:in `<main>'
      01 (See full trace by running task with --trace)
@kaydanzie kaydanzie changed the title Fatal error when running cap production deploy: LoadError: cannot load such file -- rubocop/rake_task Fatal error when deploying production: LoadError: cannot load such file -- rubocop/rake_task Aug 25, 2017
@kaydanzie kaydanzie added the bug label Aug 25, 2017
@tatwell
Copy link
Contributor

tatwell commented Aug 25, 2017

The configuration looks identical to Cascade Assets where we are not hitting this error. I wonder if Rails 5 changed the way it loads libraries so that it now preloads all lib/tasks files.

If it were to do something like this, it would explain why it executes require 'rubocop/rake_task' in this case causing the error and not in Cascade Assets.

@tatwell
Copy link
Contributor

tatwell commented Aug 25, 2017

Try moving the require statement under the task block as suggested here:

# Add additional test suite definitions to the default test task here
namespace :test do
  desc 'Runs RuboCop on specified directories'
  RuboCop::RakeTask.new(:rubocop) do |task|
    require 'rubocop/rake_task'

kaydanzie pushed a commit that referenced this issue Aug 25, 2017
@tatwell
Copy link
Contributor

tatwell commented Aug 25, 2017

I think the explanation is in here somewhere:

@kaydanzie
Copy link
Author

After a little research, I haven't come across any good workarounds. It's hard to find anyone reporting a similar issue from what I can tell. I am not familiar with capistrano at all or configuring deployment.

The temporary resolution at this point is just to remove the group :test from the Gemfile for rubocop.

@tatwell
Copy link
Contributor

tatwell commented Aug 25, 2017

That works for me for now. Leave this issue open and I expect an answer will turn up eventually.

@kaydanzie
Copy link
Author

Came across this again in Newsroom, which is also running Rails 5. I resolved it by following the recommendation in this issue to move the rubocop gem outside the test group in the Gemfile. There isn't anything in the Rubocop documentation or issues that offers a good recommendation on how to handle. Since it's not really a big deal to require the gem in all environments, we're just going to leave it there for now and close this issue.

@diasjorge
Copy link

For anyone that ends up here I found this an acceptable solution.

begin
  require 'rubocop/rake_task'
  RuboCop::RakeTask.new do |t|
    t.options = ['--display-cop-names']
  end
rescue LoadError
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants