Gem::Requirement::BadRequirementError on fly deply

I have an existing application and just added fly.io to it with fly launch, after that command succeeded. After that just executed fly deploy and got this error:

==> Verifying app config
--> Verified app config
==> Building image
Remote builder fly-builder-ancient-snow-8956 ready
==> Creating build context
--> Creating build context done
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
Sending build context to Docker daemon  1.326MB
Step 1/30 : ARG RUBY_VERSION=3.1.3
Step 2/30 : FROM ruby:$RUBY_VERSION-slim as base
 ---> 5be81ee0c666
Step 3/30 : LABEL fly_launch_runtime="rails"
 ---> Using cache
 ---> 25a5b500cd52
Step 4/30 : WORKDIR /rails
 ---> Using cache
 ---> 00827e4dfe63
Step 5/30 : ENV RAILS_ENV="production"     BUNDLE_PATH="vendor/bundle"     BUNDLE_WITHOUT="development:test"
 ---> Using cache
 ---> d03b999a1644
Step 6/30 : ARG BUNDLER_VERSION=2.3.9
 ---> Using cache
 ---> 11e7e7bce5fb
Step 7/30 : RUN gem update --system --no-document &&     gem install -N bundler -v ${BUNDLER_VERSION}
 ---> Using cache
 ---> c605ffa5500a
Step 8/30 : FROM base as build
 ---> c605ffa5500a
Step 9/30 : RUN apt-get update -qq &&     apt-get install --no-install-recommends -y build-essential curl git libpq-dev node-gyp pkg-config python-is-python3 unzip
 ---> Using cache
 ---> f52562d52765
Step 10/30 : ARG NODE_VERSION=16.17.0
 ---> Using cache
 ---> 542db94a9c08
Step 11/30 : ARG YARN_VERSION=1.22.19
 ---> Using cache
 ---> cf321f0eff1c
Step 12/30 : RUN curl -fsSL https://fnm.vercel.app/install | bash &&     /root/.local/share/fnm/fnm install $NODE_VERSION
 ---> Using cache
 ---> 8459a36779ec
Step 13/30 : ENV PATH=/root/.local/share/fnm/aliases/default/bin/:$PATH
 ---> Using cache
 ---> 9b47bc024f09
Step 14/30 : RUN npm install -g yarn@$YARN_VERSION
 ---> Using cache
 ---> a9d515e1a4e3
Step 15/30 : COPY Gemfile Gemfile.lock ./
 ---> Using cache
 ---> b0134304bd37
Step 16/30 : RUN bundle _${BUNDLER_VERSION}_ install &&     bundle exec bootsnap precompile --gemfile
 ---> Running in 81797082f712
/usr/local/lib/ruby/site_ruby/3.1.0/rubygems/requirement.rb:106:in `parse': Illformed requirement [""] (Gem::Requirement::BadRequirementError)
        from /usr/local/lib/ruby/site_ruby/3.1.0/rubygems/requirement.rb:138:in `block in initialize'
        from /usr/local/lib/ruby/site_ruby/3.1.0/rubygems/requirement.rb:138:in `map!'
        from /usr/local/lib/ruby/site_ruby/3.1.0/rubygems/requirement.rb:138:in `initialize'
        from /usr/local/lib/ruby/site_ruby/3.1.0/rubygems/requirement.rb:63:in `new'
        from /usr/local/lib/ruby/site_ruby/3.1.0/rubygems/requirement.rb:63:in `create'
        from /usr/local/lib/ruby/site_ruby/3.1.0/rubygems/dependency.rb:56:in `initialize'
        from /usr/local/lib/ruby/site_ruby/3.1.0/rubygems.rb:249:in `new'
        from /usr/local/lib/ruby/site_ruby/3.1.0/rubygems.rb:249:in `find_spec_for_exe'
        from /usr/local/lib/ruby/site_ruby/3.1.0/rubygems.rb:282:in `activate_bin_path'
        from /usr/local/bundle/bin/bundle:25:in `<main>'
Error failed to fetch an image or build from source: error building: error rendering build status stream: The command '/bin/sh -c bundle _${BUNDLER_VERSION}_ install &&     bundle exec bootsnap precompile --gemfile' returned a non-zero code: 1

I’ve seen problems like this before, I don’t know what causes it, but I know what normally fixes it.

Delete (or rename) your Gemfile.lock, run bundle install (or update), and redeploy. Not very satisfying (feels like “turn your machine off and back on again”, but ¯\_(ツ)_/¯ )

Here is an example (3 years ago, Heroku), ruby on rails - Fix for 'Gem::Requirement::BadRequirementError: Illformed requirement [">=1 <2"]' error - Stack Overflow

Hi, thanks for the help, unfortunately this didn’t work for me, still the same error.

Any chance you can post your gemfile?

This link is interesting: `parse': Illformed requirement ["2.0.0-alpha"] (Gem::Requirement::BadRequirementError) · Issue #193 · rubysec/bundler-audit · GitHub

In that problem it’s:

parse': Illformed requirement ["2.0.0-alpha"]

but your problem is empty string. Sounds like you are missing something populating your ruby version.

Other things to try:

gem update --system --no-document
gem update bundler

… and then removing Gemfile.lock, run bundle update, then fly deploy.

Thanks for the help, but again, this unfortunately didn’t work.

Unfortunately, a stack traceback alone isn’t enough to debug this issue. Providing your Gemfile may help me reproduce and diagnose the problem.

Alternately, try the first example here: Minimal Rails application · Fly Docs, and if that works, try other examples: Cookbooks · Fly Docs

1 Like

Here’s my Gemfile, hope it helps, and thanks for helping me out.

source 'https://rubygems.org'
# git_source(:github) { |repo| 'https://github.com/#{repo}.git' }

ruby '3.1.3'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 7.0.4', '>= 7.0.4.2'

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem 'sprockets-rails'

# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'

# Use the Puma web server [https://github.com/puma/puma]
gem 'puma', '~> 5.0'

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem 'importmap-rails'

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem 'turbo-rails'

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem 'stimulus-rails'

# Use Tailwind CSS [https://github.com/rails/tailwindcss-rails]
gem 'tailwindcss-rails'

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem 'jbuilder'

# Use Redis adapter to run Action Cable in production
gem 'redis', '~> 4.0'

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem 'kredis'

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem 'bcrypt', '~> 3.1.7'

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[ mingw mswin x64_mingw jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', require: false

gem 'money'

gem 'view_component'

gem 'devise', github: 'heartcombo/devise', branch: 'main'
gem 'responders', '~> 3.1.0'

# Use Sass to process CSS
# gem 'sassc-rails'

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem 'image_processing', '~> 1.2'

gem 'administrate'

group :development, :test do
  gem 'pry', platforms: %i[ mri mingw x64_mingw ]
end

group :development do
  # Use console on exceptions pages [https://github.com/rails/web-console]
  gem 'web-console'

  # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
  gem 'rack-mini-profiler'

  # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
  # gem 'spring'

  gem 'letter_opener'
end

group :test do
  # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
  gem 'capybara'
  gem 'selenium-webdriver'
  gem 'webdrivers'
  gem 'simplecov'
  gem 'shoulda-context'
  gem 'shoulda-matchers'
end

Unfortunately, all I can report so far is that I’ve failed to reproduce the problem. I’ve used your Gemfile, your version of Ruby, and your version of bundler.

What that means is that further testing and progress needs to be done on your machine. Fortunately this isn’t as hard as it sounds.

Since you haven’t gotten very far, I recommend that you destroy your fly app, database, and redis instance. Particularly if you want to stay initially in the free tier. Then create a new app, and during launch create a new database and redis instance (don’t worry about them too much, you can throw them away later too when you are ready to deploy):

rails new demo --css tailwind
cd demo
echo 'Rails.application.routes.draw { root "rails/welcome#index" }' > config/routes.rb
bundle add dockerfile-rails --optimistic --group development
bin/rails generate dockerfile --postgresql
fly launch
fly deploy

This should work, and when you visit your site it will show the Rails splash screen.

Next, save your state. git add . followed by git commit -m demo.

Now copy in your Gemfile from your application into this demo and redploy. If it fails, use git diff to see what changed in your gemfile and experiment. If it succeeds, start copying more of your application into this demo and redeploy.

I’ll be interested in hearing your results.