fix — Gem dependency’ ruby version is not compatible with ruby version the application is using. Take Rubocop for example.

涓 / Lynn Chang
Lynn’s dev blog
Published in
2 min readMay 7, 2021
Photo by John Schnobrich on Unsplash
warning: parser/current is loading parser/ruby26, which recognizes
warning: 2.6.7-compliant syntax, but you are running 2.6.6.
warning: please seehttps://github.com/whitequark/parser#compatibility-with-ruby-mri.

To Reproduce

There are two situations that will show the warning message above.

  1. Open VSCode. Then the bottom-right corner will show the warning message.
  2. Open the terminal. Then execute rubocop -v , the warning message will show also.

Reason

This happened after upgrading rubocop version from 1.3 to 1.12.1 .

rubocop 1.12.1 depends on parser 3.0.1 .

When your ruby version is 2.6.x , parser 3.0.0 will recognize ruby 2.6.6 . (check on the source code)

After parser bumped version to 3.0.1 , ruby version that parser 3.0.1 recognizes changes from 2.6.6 to 2.6.7 . (check on the source code)

However, ruby version of our application now is 2.6.6 . That's why the warning message show up.

How to solve

In this case, it’s not a good idea to change ruby version of the application only because of a gem version problem.

On the other hand, we prefer to use the newer version of rubocop.

So we choose to lock parser version at 3.0.0.0 .

# Gemfilegroup :development do
# other gems...
gem 'parser', '3.0.0.0' # fix rubocop dependency
end

Then run bundle. You might see the message after running bundle:

You have requested:
parser = 3.0.0.0
The bundle currently has parser locked at 3.0.1.0.
Try running `bundle update parser`
If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`

Just follow the message, and run bundle update parser .

If run successfully, you can see:

Note: parser version regressed from 3.0.1.0 to 3.0.0.0
Bundle updated!

Then check if the warning message will show up:

$ rubocop -v
#=> 1.12.1

The warning messages disappear 🎉

--

--

涓 / Lynn Chang
Lynn’s dev blog

A software engineer who loves writing and cares about mental health and life meaning.