2014-10-07 84 views
0

我正在開發一個Rails引擎(目前使用Rails 4.1.6)。如何解決「NameError:未初始化的常量Thor :: Base」錯誤?

$ bundle exec rake app:db:migrate --trace 
** Invoke load_app (first_time) 
** Execute load_app 
rake aborted! 
NameError: uninitialized constant Thor::Base 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/ui/shell.rb:12:in `initialize' 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/gem_helper.rb:26:in `new' 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/gem_helper.rb:26:in `initialize' 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/gem_helper.rb:13:in `new' 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/gem_helper.rb:13:in `install_tasks' 
/Users/andrew/example_rails_engine/Rakefile:10:in `<top (required)>' 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/rake_module.rb:28:in `load' 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/rake_module.rb:28:in `load_rakefile' 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:687:in `raw_load_rakefile' 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:94:in `block in load_rakefile' 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling' 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:93:in `load_rakefile' 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:77:in `block in run' 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling' 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/lib/rake/application.rb:75:in `run' 
/Users/andrew/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rake-10.3.2/bin/rake:33:in `<top (required)>' 
/Users/andrew/.rbenv/versions/2.1.3/bin/rake:23:in `load' 
/Users/andrew/.rbenv/versions/2.1.3/bin/rake:23:in `<main>' 

我的Rakefile如下::

begin 
    require 'bundler/setup' 
rescue LoadError 
    puts 'You must `gem install bundler` and `bundle install` to run rake tasks' 
end 

APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__) 
load 'rails/tasks/engine.rake' 

Bundler::GemHelper.install_tasks 

此錯誤是沒有意義的,我當我嘗試運行任何Rake任務,我得到這個錯誤。我猜Thor是Rails Rake任務的依賴。這個錯誤來自哪裏,我該如何解決它?

+0

'thor'是導軌的寶石生成器被寫入。但我並不真正瞭解發生了什麼。如果我用'rails plugin new some_engine'自己創建一個引擎,我可以成功運行'bundle exec rake app:db:migrate'。也許你添加了一些其他的代碼,但是沒有向我們展示,它正在觸發這個問題 - 雖然堆棧跟蹤並沒有真正給我們提供這方面的線索。嗯,神祕。我想知道你是否有某種方式使用不兼容的寶石版本。爲了確保你擁有所有寶石的最新版本,我會運行一個「軟件包更新」,但是我懷疑這無濟於事。 – jrochkind 2014-10-07 06:03:41

+0

https://github.com/bundler/bundler/issues/2901 - 也許有關... – 2014-10-07 06:25:27

+0

要麼做@jrochkind建議的,要麼嘗試在'Gemfile'中添加'thor' gem。 – 2014-10-07 13:06:32

回答

0

這似乎是一個問題有兩種:

衛隊列出雷神作爲依賴,而廠商捆紮機自身的托爾的版本,造成某種衝突。

我能夠通過改變在其中代碼被加載的順序temprorarily解決該問題:上述這些行Bundler::GemHelper.install_tasks

移動這一行

APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__) 
load 'rails/tasks/engine.rake' 
0

加入

require 'thor' 

RakeFile

Bundler::GemHelper.install_tasks 

固定的問題,對我來說

相關問題