Skip to content
Latchkey

Rake "aborted! LoadError: cannot load such file" in CI

A rake task tried to require a file or library that Ruby could not find on the load path. The rake run aborts and prints the missing path, which is the gem or file that was never required through the bundle.

What this error means

A rake step fails with "rake aborted!" followed by "LoadError: cannot load such file -- X" and a backtrace pointing into the Rakefile or a required task file.

bundler
rake aborted!
LoadError: cannot load such file -- dotenv/tasks
/home/runner/work/app/app/Rakefile:4:in `require'

Common causes

The required gem is not in the active groups

The Rakefile requires a gem that lives in a Gemfile group CI excluded (for example development), so it is not installed for the task.

rake ran without the bundle

rake was invoked without bundle exec, so the bundled load path was not set and the require failed.

How to fix it

Run rake through Bundler

  1. Invoke the task with bundle exec so the bundle load path is active.
  2. Ensure the required gem is in a group CI installs.
  3. Re-run so the require resolves.
Terminal
bundle exec rake assets:precompile

Install the group the task needs

If the require is in a Rakefile loaded everywhere, do not exclude its group, or move the require behind a group check.

Terminal
bundle config set --local without ''
bundle install

How to prevent it

  • Run rake via bundle exec so the load path is correct.
  • Keep gems required at Rakefile load time in installed groups.
  • Guard optional requires so excluded groups do not break tasks.

Frequently asked questions

What causes ""rake aborted! ... cannot load such file""?
The Rakefile requires a gem that lives in a Gemfile group CI excluded (for example development), so it is not installed for the task.
How do I fix "rake aborted! ... cannot load such file"?
Run rake through Bundler

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card