0

I've recently updated our Gemfile as pry-byebug and bye-bug were causing Rubymine to crash for some of my colleagues. Since there are some of us that use other editors I've added an environment variable to our Gemfile:

if ENV["USE_DEBUGGER"]
  gem "pry-byebug"
  gem "byebug"
end

This worked fine in our local machines but deploying to Heroku causes the following error: gist

I've tried running bundle install and committing a new Gemfile.lock but that changes nothing. Getting rid of the control flow declaration or simply removing the gems fixes the issue.It's worth nothing that in that same commit I bumped the required ruby version to 2.2.0

Is there any way to use conditional statements in the Gemfile without blowing Heroku up?

Gus
  • 56
  • 6
  • Almost immediately after posting this question I've just realised why this is happening: The env variable is defined in my local repo, which causes Gemfile.lock to include both gems, however since the variable is not defined in Heroku the gems are not installed by bundle but are still required by Gemfile.lock, causing all kind of issues... – Gus Jan 27 '15 at 14:27

2 Answers2

0

Wrap the conditional in a group and try to BUNDLE_WITHOUT on deployment. ref

group :byebug do
  if ENV["USE_DEBUGGER"]
    gem "pry-byebug"
    gem "byebug"
  end
end

heroku config:add BUNDLE_WITHOUT="byebug"

eabraham
  • 4,094
  • 1
  • 23
  • 29
  • Hey, thanks for your answer. I forgot to mention both gems are in the `development` group, and as you can see in the gist I'm already running BUNDLE_WITHOUT="development:test" – So in theory these gems shouldn't be installed but somehow I still get the conflict. – Gus Jan 27 '15 at 14:56
  • Ok, sorry I missed that. Yeah my next guess was the Gemfile.lock. Have you been able to resolve the deployment issue? – eabraham Jan 27 '15 at 15:05
0

Alright so after juggling with RubyMine I realised the problem occurs when requireing pry and any other related debugging gems. I managed to fix this by updating my Gemfile to the following:

  if ENV["USE_DEBUGGER"]
    gem "pry-byebug"
    gem "byebug"
  else
    gem "pry-byebug", require: false
    gem "byebug", require: false
  end

I hope this helps anybody facing a similar issue.

Gus
  • 56
  • 6