Ruby 3 overcommit & psych issue

1.4k views Asked by At

I am upgrading a Rails project to Ruby 3.1.2, from 2.6.6. I initially ran into this problem, but fixed it with adding gem 'psych', '< 4' into the Gemfile. I should note that an answer there mentioned downgrading to Ruby 3.0.3, but that does not fix my issue.

After adding that, the project worked fine regarding Psych. Unfortunately, when trying to commit/push, the overcommit hook returns this error:

/.rbenv/versions/3.1.2/lib/ruby/3.1.0/bundler/runtime.rb:309:in 'check_for_activated_spec!': You have already activated psych 4.0.4, but your Gemfile requires psych 3.3.2. Prepending 'bundle exec' to your command may solve this. (Gem::LoadError)

I also tried changing overcommit's version and got this error: Since "psych" is a default gem, you can either remove your dependency on it or try updating to a newer version of bundler that supports psych as a default gem.

Is there any way to fix this, or a specific overcommit version that would bypass this error?

1

There are 1 answers

0
Tanmay Jain On

Came across similar issue. So, posting here in case it may help somebody.

With Ruby 3, you need to add psych ~>3.0 to the Gemfile explicitly, because the default version of psych which comes bundled with Ruby 3 starts giving errors as it doesn't quite understand how to handle aliases.

If you still wish to use default psych which comes bundled in with Ruby 3. You can load your YAML files like: YAML.load_file(file_path, aliases: true).

In my case, I had dependencies loading YAML files so I decided to downgrade the psych version instead of loading YAML file with aliases: true.