Skip to content

Different version of standard gems loaded by Spring and Bundler #603

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

Closed
scottmacpherson opened this issue Nov 6, 2019 · 1 comment
Closed

Comments

@scottmacpherson
Copy link

scottmacpherson commented Nov 6, 2019

As Spring loads before Bundler and therefore relies on vanilla RubyGems to load dependencies, Spring can end up loading different versions of standard gems from the main Rails application.

This is noticable with FileUtils: version 1.1.0 shipped with Ruby 2.6.5, but the latest version is 1.3.0:

$ gem list fileutils
fileutils (1.3.0, default: 1.1.0)
$ ruby --version
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]
$ spring --version
Spring version 2.1.0

RubyGems defaults to loading the latest installed version of a required gem so when Spring boots and requires FileUtils, version 1.3.0 is loaded. However once inside the full Rails application and in the hands of Bundler, requiring FileUtils returns version 1.1.0. (Unless declared in Gemfile, Bundler will load the version of a stdlib gem that shipped with Ruby.)

This in turn leads to warnings about constants already being defined, e.g.:

/Users/scott/.rbenv/versions/2.6.5/lib/ruby/2.6.0/fileutils/version.rb:4: warning: already initialized constant FileUtils::VERSION
/Users/scott/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fileutils-1.3.0/lib/fileutils/version.rb:4: warning: previous definition of VERSION was here

This particular issue can be overcome by adding FileUtils to Gemfile, but Spring obviously relies on other gemified stdlib gems which may result in other subtle differences when running Rails with and without Spring.

@scottmacpherson
Copy link
Author

My mistake. @aar0nr has pointed out in ruby\fileutils#22 that this is likely caused by Bootsnap ignoring a bundle, and Spring is only caught up because it's the first thing in a new Rails application that loads FileUtils by name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant