当我尝试创建一个新项目时,Rails返回错误

时间:2018-11-10 00:14:02

标签: ruby-on-rails thor

Rails在我的系统上中断了,现在每当我运行rails new my_app时,它就会给我一个奇怪的Thor错误。

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)

当我运行几乎所有的rails命令,rails -v,rails s时,都会出现相同的错误。

到目前为止,我已经尝试了一些方法,包括使用rvm完全删除每个版本的ruby,然后重新安装它们,然后重新安装rails gem。没用

我真的不知道发生了什么或为什么会这样。任何帮助将不胜感激。

更新

仅意识到Rails仍然可以在现有Rails项目的范围内工作。因此,如果我在以前存在的rails项目的目录中运行rails,它就可以正常工作。

4 个答案:

答案 0 :(得分:1)

Thor是Rails用来显示各种命令行消息的宝石。

它表示您正在使用thor-0.20.1

我相信今天发布了Thor版本。以前的版本Thor-0.20.0于一年前发布。 0.20.0也是我正在使用的版本。

thor-0.20.1中可能有一个错误

您可以尝试使用捆绑程序和Gemfile强制您的应用使用thor-0.20.0

答案 1 :(得分:1)

已经发布了新版本的thor。 只需运行:

gem update thor

答案 2 :(得分:0)

我遇到了完全相同的问题,并且Rails不会接受任何命令(rails s,rails new应用程序)等。使用ruby 2.5.3和rails 5.2.1。这是由于thor-0.20.1越野车

因此,可通过以下方式将其恢复为thor-0.20.0: -卸载宝石(但在询问时不要删除可执行文件) -gem install thor -v 0.20.1

它将允许您创建一个新项目,但是请记住,Gemfile.lock文件会自动将版本更改为thor-0.20.1(我不知道为什么)。因此,请确保再次将其更改回0.20.0。

答案 3 :(得分:0)

对我来说,解决方案是删除版本的gem Thor:

$ gem卸载

选择要卸载的gem:  1. thor-0.20.0  2. thor-0.20.1  3.所有版本

  

2   成功卸载了thor-0.20.1