본문 바로가기
Ruby on Jets

bundler 오류 해결하기 feat. 디펜던시 지옥

by 혜리루 2020. 2. 19.

1.서론

저는 오늘도 평화롭게 jets 프로젝트에 gem을 추가하고 있었습니다.

google oauth2를 이용한 로그인 기능을 구현하기 위해 omniauth-google-oauth2라는 gem을 사용하고 싶었기 때문이죠.

 

그래서 아래처럼 gemfile에 gem 'omniauth-google-oauth2' 라는 문장을 추가하고

bundle install 커맨드를 이용해서 gem을 설치했습니다.

 

그랬더니 아래처럼 뭔가 굉장한 실패 메시지가 쭉쭉 나옵니다.

❯ bundle install
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
Bundler could not find compatible versions for gem "hashie":
  In snapshot (Gemfile.lock):
    hashie (= 4.1.0)

  In Gemfile:
    jets was resolved to 2.3.12, which depends on
      hashie

    omniauth-google-oauth2 was resolved to 0.2.4, which depends on
      omniauth (~> 1.0) was resolved to 1.1.3, which depends on
        hashie (~> 1.2)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

Bundler could not find compatible versions for gem "rack":
  In snapshot (Gemfile.lock):
    rack (= 2.2.2)

  In Gemfile:
    jets was resolved to 2.3.12, which depends on
      actionpack (~> 6.0.0) was resolved to 6.0.2.1, which depends on
        rack (~> 2.0, >= 2.0.8)

    omniauth-google-oauth2 was resolved to 0.2.4, which depends on
      omniauth (~> 1.0) was resolved to 1.2.1, which depends on
        rack (~> 1.0)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

당황하지 않고 마지막 줄을 대충 보니 bundle update 커맨드를 사용하면 문제가 해결 될 수도 있다고 합니다.

 

bundle update를 해보았습니다.

 

성공적으로 bundle이 설치되었습니다.

 

뭐야 별거 아니었네요 ㅎㅎㅎ 짝짝짝

 

이제 서버를 실행해봅시다.

> jets s
NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01.
Gem::Specification#rubyforge_project= called from /Users/haeree/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/specifications/mimemagic-0.3.3.gemspec:16.
You have already activated hashie 4.1.0, but your Gemfile requires hashie 3.6.0. Prepending `bundle exec` to your command may solve this.
WARNING: Unable to require "bundler/setup"
There may be something funny with your ruby and bundler setup.
You can try upgrading bundler and rubygems:

    gem update --system
    gem install bundler

Here are some links that may be helpful:

* https://bundler.io/blog/2019/01/03/announcing-bundler-2.html
* https://community.rubyonjets.com/t/jets-1-9-8-install-issue-bundler-setup-missing/185/2

Also, running bundle exec in front of your command may remove this message.

You have already activated hashie 4.1.0, but your Gemfile requires hashie 3.6.0. Prepending `bundle exec` to your command may solve this.
WARNING: Unable to require "bundler/setup"
There may be something funny with your ruby and bundler setup.
You can try upgrading bundler and rubygems:

    gem update --system
    gem install bundler

Here are some links that may be helpful:

* https://bundler.io/blog/2019/01/03/announcing-bundler-2.html
* https://community.rubyonjets.com/t/jets-1-9-8-install-issue-bundler-setup-missing/185/2

Also, running bundle exec in front of your command may remove this message.

Traceback (most recent call last):
        5: from /Users/haeree/.rbenv/versions/2.5.0/bin/jets:23:in `<main>'
        4: from /Users/haeree/.rbenv/versions/2.5.0/bin/jets:23:in `load'
        3: from /Users/haeree/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/jets-2.3.12/exe/jets:13:in `<top (required)>'
        2: from /Users/haeree/.rbenv/versions/2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:35:in `require'
        1: from /Users/haeree/.rbenv/versions/2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:168:in `rescue in require'
/Users/haeree/.rbenv/versions/2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:168:in `require': cannot load such file -- jets (LoadError)

뭔가 전자와 비등하게 굉장한 메시지가 나왔습니다.

후.. 그치만 이번에도 당황하지 않고 메시지가 하라는대로 하면 될 것입니다.

 

bundler에 문제가 있을 수도 있으니 번들러와 젬들을 업그레이드 해보라네요.

한번 해보죠.

 

일단 하라는 대로 했고 다시 서버를 실행해보겠습니다.

 

> jets s
NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01.
Gem::Specification#rubyforge_project= called from /Users/haeree/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/specifications/mimemagic-0.3.3.gemspec:16.
You have already activated hashie 4.1.0, but your Gemfile requires hashie 3.6.0. Prepending `bundle exec` to your command may solve this.
WARNING: Unable to require "bundler/setup"
There may be something funny with your ruby and bundler setup.
You can try upgrading bundler and rubygems:

    gem update --system
    gem install bundler

Here are some links that may be helpful:

* https://bundler.io/blog/2019/01/03/announcing-bundler-2.html
* https://community.rubyonjets.com/t/jets-1-9-8-install-issue-bundler-setup-missing/185/2

Also, running bundle exec in front of your command may remove this message.

You have already activated hashie 4.1.0, but your Gemfile requires hashie 3.6.0. Prepending `bundle exec` to your command may solve this.
WARNING: Unable to require "bundler/setup"
There may be something funny with your ruby and bundler setup.
You can try upgrading bundler and rubygems:

    gem update --system
    gem install bundler

Here are some links that may be helpful:

* https://bundler.io/blog/2019/01/03/announcing-bundler-2.html
* https://community.rubyonjets.com/t/jets-1-9-8-install-issue-bundler-setup-missing/185/2

Also, running bundle exec in front of your command may remove this message.

Traceback (most recent call last):
        5: from /Users/haeree/.rbenv/versions/2.5.0/bin/jets:23:in `<main>'
        4: from /Users/haeree/.rbenv/versions/2.5.0/bin/jets:23:in `load'
        3: from /Users/haeree/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/jets-2.3.12/exe/jets:13:in `<top (required)>'
        2: from /Users/haeree/.rbenv/versions/2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:35:in `require'
        1: from /Users/haeree/.rbenv/versions/2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:168:in `rescue in require'
/Users/haeree/.rbenv/versions/2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:168:in `require': cannot load such file -- jets (LoadError)

ㅎㅎ;;;; 슬슬 땀이 납니다...

 

하지만 저희는 마지막 카드가 남았습니다.

메시지가 커맨드 앞에 bundle exec 을 붙여서 실행하면 될지도 모른다고 합니다.

 

한번 하라는대로 해보았습니다.

실행은 잘 되네요. 하지만 이 찝찝함을 이루 말할 수 없습니다.

앞으로 모든 jets 명령어에 bundle exec을 붙여서 실행할 수는 없습니다..

 

어쩔 수 없이 정석대로 하나씩 뜯어보면서 오류를 해결해 보겠습니다.

 

2. bundle exec

먼저 이 bundle exec이라는 놈부터 살펴봐야겠습니다. 뭔데 이놈이 오류를 해결했을까요?

 

This command executes the command, making all gems specified in the Gemfile(5) available to require in Ruby programs.

Essentially, if you would normally have run something like rspec spec/my_spec.rb, and you want to use the gems specified in the Gemfile(5) and installed via bundle install(1), you should run bundle exec rspec spec/my_spec.rb.

 

bundle exec이라는 명령어는 gemfile안에 있는 gem들을 모두 require할 수 있게 만든다고 합니다.

그리고 평소에 쓰던 gem의 버전과 프로젝트 환경에서 쓰는 gem의 버전이 다른 경우 프로젝트 안에 있는 gemfile에 명시된 버전에 따라 gem을 사용할 수 있게 되는 것 같습니다.

 

오류 로그를 잘 보니 "WARNING: Unable to require "bundler/setup" 이런 문장이 있습니다. bundle exec이 이 bundler/setup을 require하는걸 도와줬나봅니다.

 

 

3. 오류 메시지 뜯어보기

아직 여전히 어떻게 해결해야할지 모르겠으니 메시지를 좀 더 살펴보았습니다.

이제 보니 두개의 메시지에 비슷한 내용이 있었습니다.

 

첫번째 메시지

Resolving dependencies...
Bundler could not find compatible versions for gem "hashie":
  In snapshot (Gemfile.lock):
    hashie (= 4.1.0)

  In Gemfile:
    jets was resolved to 2.3.12, which depends on
      hashie

    omniauth-google-oauth2 was resolved to 0.2.4, which depends on
      omniauth (~> 1.0) was resolved to 1.1.3, which depends on
        hashie (~> 1.2)

두번째 메시지

You have already activated hashie 4.1.0, but your Gemfile requires hashie 3.6.0. Prepending `bundle exec` to your command may solve this.

 

뭔지는 몰라도 hashie라는 gem이 말썽인 것 같습니다. 이친구를 수정해줘야겠습니다.

그런데 hashie는 제가 추가한 gem이 아닌데요.. gemfile을 눈 씻고 찾아봐도 hashie라는 놈은 없습니다.

 

첫번째 메시지를 보니 hashie는 jets에서 사용되고 있고

omniauth-google-oauth2에서 사용되는 omniauth에서 사용되는...

아무튼 디펜던시였습니다.

 

두번째 메시지를 보면 저는 hashie 4.1.0 버전을 활성화했는데 제 gemfil은 hashie 3.6.0버전이 필요하답니다.

그럼 필요하다는대로 3.6.0을 활성화 해주기로 합니다.

 

먼저 gemfile.lock을 살펴보겠습니다.

 

에러 메시지에서 얘기한대로 

jets와 omniauth 두가지 gem에서 hashie를 사용하고 있었는데요,

omniauth는 버전이 특정되어있는 반면 jets는 버전을 특정하지 않았기 때문에 자동으로 최신버전이 함께 설치됩니다.

 

저같은 경우에는 jets를 먼저 설치했기 때문에 omniauth2를 설치하는 과정에서

그동안 사용하던 최신 버전 hashie 4.1.0버전이 omniauth의 hashie 버전 제약과 충돌한 것으로 보입니다.

 

 

jets에서는 달리 버전에 대한 제약이 없기 때문에 3.6.0으로 설정을 해주겠습니다.

gemfile에 hashie 버전이 3.6.0으로 설정이 되어있는지 확인하고

3.6.0 버전의 hashie가 있는지 확인하고 없다면 설치해줍니다.

>gem list
>gem install hashie -v 3.6.0 

그리고 4.1.0 버전은 삭제해줍시다.

>gem uninstall hashie -v 4.1.0

 

시험삼아 콘솔을 열어봅시다

잘 열리네요!

 

 

다행히 이번에는 dependency끼리 버전의 교집합이 있어서 쉽게 해결이 가능했습니다.

서로 겹치는 버전이 없는 dependency라면 음 그때는 또 그때 공부해서 해결하도록 하겠습니다.

 

사실 이 에러 해결하느라고 git repo를 한 3번은 갈아치웠네요..

에러 메시지에 다 나와있는 문제였는데요..

여러분도 문제 해결할때는 에러 메시지부터 꼭 잘 확인하세요 화이팅!

댓글