Ruby on Rails error: superclass mismatch for class StringIO (TypeError)

Viewed 4307

I am getting an error while creating a ruby on rails project. In command, I created a new project by typing rails new club, then bundle. Now, when I try to create my models and controllers by typing and entering rails g resource Club name, I get this error: superclass mismatch for class StringIO (TypeError).

gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:
in `require': superclass mismatch for class StringIO (TypeError)

I don't even has a class named StringIO, so I'm not sure where it came from.

  • ruby version: 2.6.8
  • rails: 6.1.4.1
6 Answers

Try reverting to an earlier version of StringIO

gem install stringio -v 0.1.4

gem uninstall stringio # remove 3.0.0 and 3.0.1

None of the above answers worked for me. What happened for me is that I added gem 'rubocop', '~> 0.67.2', require: false to Gemfile and ran bundle install.

This version of rubocop seems to have installed psych as a dependency and then psych has a dependency on stringio and I, correct me if I'm wrong, that must be conflicting with whatever stringio version is being used by bootsnap.

Anyway, to solve it I just deleted the rubocop line I added to Gemfile and added gem 'rubocop', require: false (which installed the latest rubocop version) then ran bundle install again.

I started getting this error after updating my gems. I tried uninstalling ruby and all my gems, updating rvm, but for me the solution appeared to be updating rubygems.

gem update --system

It works for me.

My Error was: The application encountered the following error: superclass mismatch for class StringIO (TypeError)

The problem was caused by this issue https://www.redmine.org/issues/35435

It might help you. I also removed all gems related to #gem 'sdoc' It seams like by default sdoc call internally gem 'psych', which is the gem uses the StringIO and both have different version you can check the difference in your GemFile.Lock to see difference between your 2 versions.

As others have said on @jason-lee answer, for many people, this can be fixed just by uninstalling the existing stringio then running bundle install again.

    gem uninstall stringio
    bundle

The error was gone when I bumped Ruby version to 3.0.4 from 2.7.6

Related