Rails returns error when I try to create a new project

Viewed 874

Rails broke on my system and now whenever I run rails new my_app it gives me a weird Thor error.

joshuahadik -> rails new hello_world
Traceback (most recent call last):
    21: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `<main>'
    20: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `eval'
    19: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/bin/rails:23:in `<main>'
    18: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/bin/rails:23:in `load'
    17: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/railties-5.2.1/exe/rails:10:in `<top (required)>'
    16: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    15: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    14: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/railties-5.2.1/lib/rails/cli.rb:12:in `<top (required)>'
    13: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    12: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    11: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/railties-5.2.1/lib/rails/command.rb:9:in `<top (required)>'
    10: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
     9: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
     8: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/thor-0.20.1/lib/thor.rb:2:in `<top (required)>'
     7: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
     6: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
     5: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/thor-0.20.1/lib/thor/base.rb:4:in `<top (required)>'
     4: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
     3: from /Users/joshuahadik/.rvm/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
     2: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/thor-0.20.1/lib/thor/error.rb:1:in `<top (required)>'
     1: from /Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/thor-0.20.1/lib/thor/error.rb:6:in `<class:Thor>'
/Users/joshuahadik/.rvm/gems/ruby-2.5.3/gems/thor-0.20.1/lib/thor/error.rb:12:in `<module:DidYouMean>': uninitialized constant Thor::DidYouMean::SpellChecker (NameError)

I get the same error when I run pretty much any rails command, rails -v, rails s, etc.

So far I've tried a few things, including completely removing every version of ruby with rvm, then reinstalling them, then reinstalling the rails gem. Didn't work.

I really have no idea what's going on or why this is happening. Any help would be greatly appreciate.

UPDATE

Just realized that rails still works within the context of an existing rails project. So if I run rails s in the directory of a previously existing rails project it works just fine.

4 Answers

Thor is a gem that is used by Rails to show various command line messages.

It says you are using thor-0.20.1

I believe that version of Thor was released TODAY. The previous version, Thor-0.20.0 was released over a year ago. 0.20.0 is also the version I'm using.

It's likely that there is a bug in thor-0.20.1

You can try using bundler and your Gemfile to force your app to use thor-0.20.0

I ran into the exact same issue and rails wouldn't accept any command (rails s, rails new app) etc. Using ruby 2.5.3 and rails 5.2.1. It is due to the buggy thor-0.20.1

Therefore, reverted it back to thor-0.20.0 by: - gem uninstall thor (but do not remove the executables when asked) - gem install thor -v 0.20.1

It shall allow you to create a new project, however keep in mind that the Gemfile.lock file automatically changes the version to thor-0.20.1 (I don't know why). So be sure to change it back again to the 0.20.0.

A new version of thor has been released. Just run:

gem update thor

The solution for me is delete the version gem Thor:

$ gem uninstall thor

Select gem to uninstall: 1. thor-0.20.0 2. thor-0.20.1 3. All versions

2 Successfully uninstalled thor-0.20.1

Related