rubocop: Can't execute v1.34.0 with error "cannot load such file -- rubocop-rails"

I can’t run rubocop v1.34.0. Downgrading to v1.33.0, I could run it correctly.


Expected behavior

In the rails project,

  • execute % rubocop
  • then execute correctly

Actual behavior

% rubocop --debug
For /path-to/ruby-project: configuration from /path-to/ruby-project/.rubocop.yml
cannot load such file -- rubocop-rails
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/feature_loader.rb:33:in `require'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/feature_loader.rb:33:in `load'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/feature_loader.rb:21:in `load'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_loader_resolver.rb:14:in `block (2 levels) in resolve_requires'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_loader_resolver.rb:13:in `each'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_loader_resolver.rb:13:in `block in resolve_requires'
<internal:kernel>:90:in `tap'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_loader_resolver.rb:12:in `resolve_requires'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_loader.rb:46:in `load_file'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_loader.rb:104:in `configuration_from_file'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_store.rb:68:in `for_dir'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/config_store.rb:47:in `for_pwd'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/cli.rb:99:in `parallel_by_default!'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/lib/rubocop/cli.rb:46:in `run'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/exe/rubocop:19:in `block in <top (required)>'
/path-to/.rbenv/versions/3.1.1/lib/ruby/3.1.0/benchmark.rb:311:in `realtime'
/path-to/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubocop-1.34.0/exe/rubocop:19:in `<top (required)>'
/path-to/.rbenv/versions/3.1.1/bin/rubocop:25:in `load'
/path-to/.rbenv/versions/3.1.1/bin/rubocop:25:in `<main>'
Finished in 0.01386200000001736 seconds

Steps to reproduce the problem

  • Just do %rubocop

RuboCop version

% bundle exec rubocop -V
1.34.0 (using Parser 3.1.2.1, rubocop-ast 1.21.0, running on ruby 3.1.1 arm64-darwin21)
  - rubocop-rails 2.15.2

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 15 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Still getting such error with v1.60.2. I’m adding new rubocop extentions to my Gemfile (ex. ‘rubocop-rails’) and then to the .rubocop.yml. And when I try to execute rubocop - oops! cannot load such file.

But! I was able to fix this with rubocop --restart-server. In the docs I found this: https://docs.rubocop.org/rubocop/usage/server.html#restart-server

The started server does not reload the configuration file. You will need to restart the server when you upgrade RuboCop or change the RuboCop configuration.

For me @BoutPure 's answer worked rubocop --restart-server

Same issue with new rubocop-rspec 3.0.1 and rubocop 1.64.1

cannot load such file – rubocop-rspec_rails

.rubocop.yml

require:
  - rubocop-performance
  - rubocop-rails
  - rubocop-rspec
  - rubocop-rspec_rails
  - rubocop-factory_bot

Gemfile:

group :development, :test do
  gem 'debug', platforms: %i[mri mingw x64_mingw]
  gem 'factory_bot_rails'
  gem 'irb'
  gem 'reline'
  gem 'rspec-rails'
  gem 'rubocop', require: false
  gem 'rubocop-performance', require: false
  gem 'rubocop-rails', require: false
  gem 'rubocop-rspec', require: false
end

The same error.

  • Ruby 3.3.3
  • rubocop (1.64.1)
  • rubocop-rspec (3.0.1)
  • rubocop-rspec_rails (2.30.0)
  • rubocop-factory_bot (2.26.1)
# .rubocop.yml
require:
  - rubocop-performance
  - rubocop-rails
  - rubocop-rspec
  - rubocop-faker
  - rubocop-factory_bot
  - rubocop-rspec_rails
# Gemfile

group :development do
  gem 'fasterer'
  gem 'rubocop', require: false
  gem 'rubocop-factory_bot', require: false
  gem 'rubocop-faker', require: false
  gem 'rubocop-performance', require: false
  gem 'rubocop-rails', require: false
  gem 'rubocop-rspec', require: false
  gem 'rubocop-rspec_rails', require: false
bundle exec rubocop
cannot load such file -- rubocop-factory_bot
bundle exec rubocop
cannot load such file -- rubocop-rspec_rails

JFYI, RuboCop 1.34.1 has been released. Thank you.

@hiro-teaaa OK, It was reproducible. Thank you!

Can confirm this issue. It fails for any require that is placed in the .rubocop.yml config file, works fine when using the cli argument $ rubocop --require rubocop-rails --require rubocop-performance.

This error is caused by #10845. It requires backward compatibility.