'rails new' creates a `validate_default_type!': An option's default must match its type. (ArgumentError) error
Asked Answered
G

4

6

I am trying to create a new Ruby on Rails application. Every time I type in rails new after, I get this error

/usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/option.rb:130:in `validate_default_type!': An option's default must match its type. (ArgumentError)
    from /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/option.rb:113:in `validate!'
    from /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/argument.rb:24:in `initialize'
    from /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/option.rb:9:in `initialize'
    from /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/base.rb:544:in `new'
    from /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/base.rb:544:in `build_option'
    from /usr/local/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/base.rb:278:in `class_option'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/generators/base.rb:202:in `class_option'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/generators/app_base.rb:71:in `add_shared_options_for'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/generators/rails/app/app_generator.rb:160:in `<class:AppGenerator>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/generators/rails/app/app_generator.rb:159:in `<module:Generators>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/generators/rails/app/app_generator.rb:153:in `<module:Rails>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/generators/rails/app/app_generator.rb:3:in `<top (required)>'
    from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/application.rb:2:in `<top (required)>'
    from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/cli.rb:14:in `<top (required)>'
    from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.5/bin/rails:9:in `<top (required)>'
    from /usr/local/bin/rails:23:in `load'
    from /usr/local/bin/rails:23:in `<main>' 

I have Ruby on Rails installed on my computer and have written other Ruby on Rails applications. Any ideas of why I am getting this error and how can I fix it?

Genius answered 26/11, 2016 at 21:42 Comment(2)
sounds like a few others are getting the same error. It looks like it's from the Thor gem: github.com/erikhuda/thor/issues/533Quadragesimal
Possible duplicate of Error "'Validate_default_type!': An option's default must match its type (ArgumentError)" when running Ruby on Rails generate on WindowsFrontlet
T
4

It seems the latest gem release broke it. Once that gets fixed, then this error should go away.

A temporary fix if you already have a Ruby on Rails app is to set the version of Thor in your Gemfile to the last release:

gem 'thor', '0.19.1'

Alternatively if you are having trouble creating a new Ruby on Rails application, you can uninstall Thor and install an older version:

gem uninstall thor
gem install thor -v 0.19.1
Tricornered answered 26/11, 2016 at 22:7 Comment(8)
I tried gem install thor '0.19.1', but get an error that the gem cannot be foundGenius
This goes in your Gemfile. It's not a command for the terminal.Tricornered
How would I find the gem file if I cannot create the app?Genius
The app should have generated fine (mine do) but when I run a generator, then it fails. Share your whole logs before the error?Tricornered
I thought I did above. If not where do I get to get the entire log?Genius
You just captured the error, not the command you ran or anything before the error. That's often very helpful for debugging as well.Tricornered
Let us continue this discussion in chat.Genius
Updated my instructions with a solution that should work for you.Tricornered
V
0

I had the same problem, turns out I had to uninstall thor both in my system, and in my rails app.

I also could not generate a new app so in command line, so I had to:

gem uninstall thor
gem install thor -v 0.19.1

Then rails commands works in command line again

I then generated a new rails app, but this failed to, since it get the broken version. So in my gem file I required the right version:

gem 'thor', '0.19.1'

and then run

bundle install

oh, no!

"You have requested:
  thor = 0.19.1

The bundle currently has thor locked at 0.19.2.
Try running `bundle update thor`"

so then

bundle update 

and voila!! :)

Using thor 0.19.1 (was 0.19.2)

And the failing command now runs:

rails generate rspec:install
Running via Spring preloader in process 26996
      create  .rspec
      create  spec
      create  spec/spec_helper.rb
      create  spec/rails_helper.rb
Vistula answered 27/11, 2016 at 3:37 Comment(0)
P
0

i just found thor 0.19.3 is out and works now. I'm only a week into playing around with rails so for those other newbies I didn't find any reference to thor in the gemsfile in my app but I simply added it as Benjamin showed except using 0.19.3 and did the bundle update thor and it's working now. Everything else I did before with 0.19.1 got me rails new but then failed on generating a scaffolding.

Petulah answered 27/11, 2016 at 19:56 Comment(0)
A
-1

I tried:

gem install thor '0.19.1'. 

And I got:

Could not find a valid gem '0.19.1' (>= 0) in any repository.

Erik Michaels-Ober changed the Thor gem. And rails new works only with Ruby on Rails v. 5.0. And there are no old versions of this gem. Ruby on Rails now work only with version 5.0. Ruby on Rails 4.2.6 is over. Erik Michaels-Ober and gem kills old versions of Ruby on Rails.

Alumna answered 26/11, 2016 at 22:39 Comment(2)
Your command is incorrect. You need "gem install thor -v 0.19.1"Tricornered
Thanks! gem install thor -v 0.19.1 is a solution of problem/ I had the same probltm as Aaron and you show the solutionFlyback

© 2022 - 2024 — McMap. All rights reserved.