Bundler "Bundler::GemspecError" - Invalid gemspec in CI
Bundler evaluates each .gemspec as Ruby while resolving, and one of them raised an exception. The gemspec runs real code - a git shell-out, a File.read, a require - and that code failed on the runner.
What this error means
bundle install or bundle exec fails with Bundler::GemspecError naming a specific .gemspec and an underlying error. It is a load-time failure of the gemspec itself, not a version conflict.
Bundler::GemspecError: There was an error while loading `mygem.gemspec`:
No such file or directory - git ls-files. Bundler cannot continue.
# from /app/mygem.gemspec:12:in `<main>'Common causes
gemspec shells out to git for the file list
Many gemspecs set spec.files = git ls-files. On a runner without git, or outside a git checkout (a downloaded tarball), that shell-out fails and the gemspec raises.
gemspec reads a file that is not present
A gemspec that reads VERSION, a README, or another file at load time raises if that file was not checked out or was excluded from the package.
How to fix it
Make the gemspec evaluable on the runner
- If it runs git ls-files, install git and ensure the build runs inside the git checkout.
- If it reads a file, confirm that file is present (not gitignored, not excluded from the gem).
- For a path/git-sourced local gem, fix its gemspec so it does not raise when files are missing.
Install git for git-based gemspecs
# Debian/Ubuntu
apt-get update && apt-get install -y git
bundle installHow to prevent it
- Avoid shelling out in gemspecs, or guard the shell-out so it degrades gracefully.
- Bake git into images that build git-based gemspecs.
- Keep files referenced by the gemspec checked in and packaged.