'cannot load such file' error when installed with bundler in rbenv
Closed this issue · 6 comments
Hello there!
I stumbled upon this gem while looking for a solution to, well, the exact problem this seems intended to solve! I work on a rails project, so whenever I'm debugging something, It's always a pain to step over 500,000 activerecord frames when trying to trace something, so being able to just jump over them based on their source file path would save me a ton of time and annoyance.
Unfortunately, I can't actually use this, as ruby seems to have trouble requiring
it. I installed it with bundler, adding gem 'byebug-skipper'
to my Gemfile, and running bundle install
as normal. I also use rbenv for version management since, which I suspect is part of the issue. When ruby tries to require it, I get the following error (RBENV_PATH
is just .rbenv
directory in my homedir)
$ ruby scratch.rb
<internal:RBENV_PATH/versions/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- byebug-skipper (LoadError)
from <internal:RBENV_PATH/versions/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from scratch.rb:3:in `<main>'
And the script I'm running to demonstrate the issue:
# scratch.rb
require 'byebug'
require 'byebug-skipper'
puts "hello"
byebug
puts "world"
I get similar results with ruby 2.6.6 (2.6.6 and 3.2.2 are the only versions I have set up locally). My gut tells me rbenv is somehow getting in the way, but I don't know enough about how that or ruby's requiring works to understand why.
Any assistance in figuring out how to get this working would be appreciated! Or if you're not maintaining this anymore, that's fine too. Have a great day! 😃
Hi Michael,
Is that output copy-pasted exactly, or did you modify the parts that say RBENV_PATH
? If it's actually outputting RBENV_PATH
then that would probably indicate that something is wrong with it. It's likely caused by using RBENV_PATH
instead of $RBENV_PATH
in your shell config somewhere.
The other thing it could be is when you run ruby scratch.rb
it can't access gems installed via Bundler. You could try bundle exec ruby scratch.rb
in the same directory as the Gemfile
, or you could try install the gem without Bundler using just gem install byebug-skipper
to make the gem available globally.
I did edit it to obscure my local file structure, it's not actually printing out RBENV_PATH
:p.
I'll try with bundle exec
and a global install when I can and let you know how it goes!
I tried it with bundle exec ruby scratch.rb
and I got a slightly different error: (also upgraded to ruby 3.2.3 since, but I doubt that makes a difference)
$ bundle exec ruby scratch.rb
<internal:RBENV_PATH/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require': cannot load such file -- byebug-skipper (LoadError)
Did you mean? byebug/skipper
from <internal:RBENV_PATH/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
from scratch.rb:2:in `<main>'
So I tried what it suggested, changing scratch.rb
to
# scratch.rb
require 'byebug'
require 'byebug/skipper'
puts "hello"
byebug
puts "world"
which gave me yet another different error
$ bundle exec ruby scratch.rb
<internal:RBENV_PATH/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require': cannot load such file -- byebug/commands/skip (LoadError)
from <internal:RBENV_PATH/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
from RBENV_PATH/versions/3.2.3/lib/ruby/gems/3.2.0/gems/byebug-skipper-0.4.0/lib/byebug/skipper.rb:30:in `<top (required)>'
from <internal:RBENV_PATH/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
from <internal:RBENV_PATH/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
from scratch.rb:2:in `<main>'
So I tried it with a non-bundle install. Made a new directory, put a .ruby-version
in it with 3.2.3
so I'm using the right version (and because i'd have to sudo the gem install otherwise).
Then I did
gem install byebug
gem install byebug-skipper
which completed succesfully.
I then ran scratch.rb
again, with require 'byebug-skipper'
and got
$ ruby scratch.rb
<internal:RBENV_PATH/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require': cannot load such file -- byebug-skipper (LoadError)
from <internal:RBENV_PATH/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
from scratch.rb:2:in `<main>'
But then I tweaked it to do require 'byebug/skipper'
(slash instead of dash) and...
$ ruby scratch.rb
hello
RBENV_PATH/versions/3.2.3/lib/ruby/gems/3.2.0/gems/byebug-11.1.3/lib/byebug/attacher.rb:14: warning: undefining the allocator of T_DATA class Byebug::ThreadsTable
RBENV_PATH/versions/3.2.3/lib/ruby/gems/3.2.0/gems/byebug-11.1.3/lib/byebug/attacher.rb:14: warning: undefining the allocator of T_DATA class Byebug::Context
[1, 6] in HOME/bb-skipper-demo/scratch.rb
1: require 'byebug'
2: require 'byebug/skipper'
3:
4: puts "hello"
5: byebug
=> 6: puts "world"
(byebug) c
world
it worked! So it seems that bundler is the issue. I switched back to my project directory (using the same rbenv-controlled version) and ruby scratch.rb
works (as expected), but bundle exec ruby scratch.rb
still errors out with
$ bundle exec ruby scratch.rb
<internal:RBENV_PATH/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require': cannot load such file -- byebug/commands/skip (LoadError)
from <internal:RBENV_PATH/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
from RBENV_PATH/versions/3.2.3/lib/ruby/gems/3.2.0/gems/byebug-skipper-0.4.0/lib/byebug/skipper.rb:30:in `<top (required)>'
from <internal:RBENV_PATH/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
from <internal:RBENV_PATH/versions/3.2.3/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
from scratch.rb:2:in `<main>'
So then I checked the byebug version in my Gemfile.lock
vs the version installed in my clean directory, and there was a difference! My bundler had 10.0.2
, and the clean install did 11.1.3
, probably had to do with how I was originally using ruby 2. So I updated my Gemfile
to specify gem 'byebug', '>= 11.1.3'
, ran bundle install
and now bundle exec ruby scratch.rb
is working as expected! I still need to test it with my rails server, but I think that's the issue.
so bottom line:
- the correct
require
syntax should berequire 'byebug/skipper'
, not'require 'byebug-skipper'
- This requires a version of byebug > 10.0.2 (not sure the exact version, but I'd guess > 11.0.0).
I'll see about submitting a PR with readme changes to that end. I'm not sure if it's possible to specify a minimum byebug version in the package definition, but that might also be wise.
Nice investigating!
Yeah, whoops, it's definitely supposed to be require 'byebug/skipper'
. I've updated README.md
for that.
When I originally wrote the code, it would have been against byebug
11.1.3 and it was pretty difficult to get it working at all (see HackyProcessor
in the source code). So I'm not surprised that it doesn't work with older versions. I should really set a minimum byebug
version in the gemspec.
Nice! thanks for taking care of that. I would have done a PR but I've been a bit under the weather lately XD.
I was planning to make a quick PR to add a pattern to the defaults for rbenv so it works out of the box for that too, so keep an eye out for that ;)