Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with Bundler.setup mangling $LOAD_PATH #5172

Closed
p8952 opened this issue Jan 11, 2015 · 2 comments
Closed

Issues with Bundler.setup mangling $LOAD_PATH #5172

p8952 opened this issue Jan 11, 2015 · 2 comments

Comments

@p8952
Copy link

p8952 commented Jan 11, 2015

I'm using Vagrant 1.6.5 in a non-standard and non-supported environment. I'm also unsure if this is an issue with Vagrant itself or Bundler.

I am using system Ruby and have installed Vagrant 1.6.5 from the 1.6.5 git tag. I have documented the specific steps I take to install Vagrant here.

When running Vagrant from a directory containing a Gemfile, or a sub-directory where the parent has a Gemfile I receive the following error:

`require': cannot load such file -- log4r (LoadError)

The error is raised from here and seems to be caused by the call to Bundler.setup here. Prior to this call my $LOAD_PATH contains the following:

/home/peter/.gem/ruby/2.0.0/gems/bundler-1.6.9/lib
/home/peter/.gem/ruby/2.0.0/extensions/x86_64-linux/2.0.0/ffi-1.9.6
/home/peter/.gem/ruby/2.0.0/gems/ffi-1.9.6/lib
/home/peter/.gem/ruby/2.0.0/gems/childprocess-0.5.5/lib
/home/peter/.gem/ruby/2.0.0/gems/erubis-2.7.0/lib
/home/peter/.gem/ruby/2.0.0/gems/i18n-0.6.11/lib
/home/peter/.gem/ruby/2.0.0/extensions/x86_64-linux/2.0.0/hitimes-1.2.2
/home/peter/.gem/ruby/2.0.0/gems/hitimes-1.2.2/lib
/home/peter/.gem/ruby/2.0.0/gems/timers-4.0.1/lib
/home/peter/.gem/ruby/2.0.0/gems/celluloid-0.16.0/lib
/home/peter/.gem/ruby/2.0.0/gems/rb-fsevent-0.9.4/lib
/home/peter/.gem/ruby/2.0.0/gems/rb-inotify-0.9.5/lib
/home/peter/.gem/ruby/2.0.0/gems/listen-2.7.12/lib
/home/peter/.gem/ruby/2.0.0/gems/hashicorp-checkpoint-0.1.4/lib
/home/peter/.gem/ruby/2.0.0/gems/log4r-1.1.10/lib
/home/peter/.gem/ruby/2.0.0/gems/net-scp-1.1.2/lib
/home/peter/.gem/ruby/2.0.0/gems/rb-kqueue-0.2.3/lib
/home/peter/.gem/ruby/2.0.0/extensions/x86_64-linux/2.0.0/wdm-0.1.0
/home/peter/.gem/ruby/2.0.0/gems/wdm-0.1.0/lib
/home/peter/.gem/ruby/2.0.0/gems/gssapi-1.0.3/lib
/home/peter/.gem/ruby/2.0.0/gems/httpclient-2.6.0.1/lib
/home/peter/.gem/ruby/2.0.0/gems/mini_portile-0.6.0/lib
/home/peter/.gem/ruby/2.0.0/extensions/x86_64-linux/2.0.0/nokogiri-1.6.3.1
/home/peter/.gem/ruby/2.0.0/gems/nokogiri-1.6.3.1/lib
/home/peter/.gem/ruby/2.0.0/gems/rubyntlm-0.1.1/lib
/home/peter/.gem/ruby/2.0.0/gems/uuidtools-2.1.5/lib
/home/peter/.gem/ruby/2.0.0/gems/builder-3.2.2/lib
/home/peter/.gem/ruby/2.0.0/gems/nori-1.1.5/lib
/home/peter/.gem/ruby/2.0.0/gems/httpi-0.9.7/lib
/home/peter/.gem/ruby/2.0.0/gems/wasabi-1.0.0/lib
/home/peter/.gem/ruby/2.0.0/gems/gyoku-1.2.2/lib
/home/peter/.gem/ruby/2.0.0/gems/akami-1.2.2/lib
/home/peter/.gem/ruby/2.0.0/gems/savon-0.9.5/lib
/home/peter/.gem/ruby/2.0.0/gems/little-plugger-1.1.3/lib
/home/peter/.gem/ruby/2.0.0/gems/multi_json-1.10.1/lib
/home/peter/.gem/ruby/2.0.0/gems/logging-1.8.2/lib
/home/peter/.gem/ruby/2.0.0/gems/winrm-1.1.3/lib
/home/peter/.gem/ruby/2.0.0/gems/vagrant-1.6.5/lib
/usr/lib64/ruby/site_ruby/2.0.0
/usr/lib64/ruby/site_ruby/2.0.0/x86_64-linux
/usr/lib64/ruby/site_ruby
/usr/lib64/ruby/vendor_ruby/2.0.0
/usr/lib64/ruby/vendor_ruby/2.0.0/x86_64-linux
/usr/lib64/ruby/vendor_ruby
/usr/lib64/ruby/2.0.0
/usr/lib64/ruby/2.0.0/x86_64-linux

However after Bundler.setup us called my $LOAD_PATH becomes:

/home/peter/.gem/ruby/2.0.0/gems/bundler-1.6.9/lib
/usr/lib64/ruby/site_ruby/2.0.0
/usr/lib64/ruby/site_ruby/2.0.0/x86_64-linux
/usr/lib64/ruby/site_ruby
/usr/lib64/ruby/vendor_ruby/2.0.0
/usr/lib64/ruby/vendor_ruby/2.0.0/x86_64-linux
/usr/lib64/ruby/vendor_ruby
/usr/lib64/ruby/2.0.0
/usr/lib64/ruby/2.0.0/x86_64-linux

Which is why Vagrant can't require log4r. When running in a directory without a Gemfile the my $LOAD_PATH remains unmodified.

I assume this is because Bundler is locking me into an environment with only the contents of the Gemfile available? I also assume for whatever reason this behaviour is not present in the versions of Vagrant which ship with their dependencies pre-packaged?

I understand my environment is non-standard and non-supported so feel free to close this if it's just a case of "Don't do that", however any help or advice is much appreciated.

@p8952
Copy link
Author

p8952 commented Jan 12, 2015

For now I'm wrapping this block of code with the following to restore the $LOAD_PATH. This seems to resolve the issue in my case.

load_path = []
$LOAD_PATH.each { |path| load_path << path }
...
load_path.each { |path| $LOAD_PATH.push(path) unless $LOAD_PATH.include?(path) }

@mitchellh
Copy link
Member

This is definitely a "don't do that". However, if you can find a way to work around it please let us know. The issue is that the existence of a Gemfile in a non-standard environment tells Vagrant to think it is in "dev mode" so it uses the bundle, assuming that all of its dependencies are in there.

@hashicorp hashicorp locked and limited conversation to collaborators Apr 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants