Skip to content
Latchkey

rake aborted! LoadError during a Rake task in CI

A Rake task aborted because a require at the top of the Rakefile or a task file could not load a file or gem. The task never ran; loading the task definitions failed first.

What this error means

A rake step prints "rake aborted!" followed by a LoadError naming the file or gem, with a Rakefile/task backtrace. Common when a task requires a gem not in the bundle or a moved file.

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

Common causes

Required gem not in the bundle

The Rakefile requires a gem (or one of its tasks files) that is not installed in the CI groups.

Not run through Bundler

rake was invoked without bundle exec, so the bundle was not set up and the require missed.

Moved or missing task file

A require_relative in the Rakefile points at a file that was renamed or not committed.

How to fix it

Bundle the dependency and run via Bundler

  1. Add the required gem to a group CI installs, then bundle install.
  2. Invoke tasks with bundle exec rake (or bin/rake).
  3. Fix any require_relative paths that point at moved/missing files.
Terminal
bundle exec rake db:seed

How to prevent it

  • Run rake through bundle exec or a binstub.
  • Keep Rakefile requires inside groups CI installs.
  • Verify the Rakefile loads on a clean checkout.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →