简体   繁体   中英

How to fix “NameError: uninitialized constant Thor::Base” error?

I am in the process of developing a Rails Engine (currently using Rails 4.1.6). I get this error when I try to run any Rake tasks:

$ 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>'

My Rakefile is as follows:

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

This error doesn't make sense to me. I'm guessing Thor is a dependency of Rails Rake tasks. Where is this error coming from and how do I fix it?

adding

 require 'thor'

to your RakeFile before

 Bundler::GemHelper.install_tasks

fixed the issue for me

This seems to be an issue with either:

Guard lists Thor as a dependency, while Bundler vendors its own version of Thor, causing some sort of conflict.

I was able to temprorarily fix the problem by changing the order in which the code is loaded:

Move this line: Bundler::GemHelper.install_tasks above these lines:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM