"rails plugin" command doesn't work with rake 0.9 #1866

rfc2822 opened this Issue Jun 26, 2011 · 35 comments


None yet

rfc2822 commented Jun 26, 2011

With this line in Gemfile:
require "rake"

$ rake -V
rake, version 0.9.2

all "rails plugin *" commands fail with this error:

/vendor/bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/commands/plugin.rb:277: Commands is not a module (TypeError)
from /vendor/bundler/ruby/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in require' from <my project path>/vendor/bundler/ruby/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:inrequire'
from /vendor/bundler/ruby/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in load_dependency' from <my project path>/vendor/bundler/ruby/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:596:innew_constants_in'
from /vendor/bundler/ruby/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in load_dependency' from <my project path>/vendor/bundler/ruby/1.8/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:inrequire'
from /vendor/bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/commands.rb:17
from script/rails:6:in `require'
from script/rails:6

When using
gem 'rake', '0.8.7'

all "rails plugin" commands work.


dyba commented Jun 28, 2011

What exactly are you trying to do? Do you have a Gemfile? The command below works fine.

rails plugin install git://github.com/mislav/will_paginate.git

rfc2822 commented Jun 28, 2011

I tried to install a plugin with a command like yours, but every command that begins with
rails plugin
fails for me. Do you want to know if the project has a Gemfile? - Yes it has but its not related to the plugin. Shall I post the Gemfile?

@rfc2822 rfc2822 closed this Jun 28, 2011

@rfc2822 rfc2822 reopened this Jun 28, 2011

rfc2822 commented Jun 28, 2011

Had no intention to close this.... may i clicked the wrong button. re-opened


dyba commented Jun 29, 2011

This is what I get when I run rails plugin install git://github.com/sbecker/asset_packager.git. Also includes running the commands bundle list and ls -R vendor. By the way, I'm running Ruby 1.9.2. I don't have the same issue. @ckidow, how about posting your app so anyone can pull it? @rfc2822, you should run the bundle list command and inform us what version of Ruby you're running.

rfc2822 commented Jun 29, 2011

(at the moment with rake 0.8.7 because I set the version in the Gemfile)
$ bundle list
Gems included by the bundle:

  • abstract (1.0.0)
  • actionmailer (3.0.9)
  • actionpack (3.0.9)
  • activemodel (3.0.9)
  • activerecord (3.0.9)
  • activeresource (3.0.9)
  • activesupport (3.0.9)
  • arel (2.0.10)
  • authlogic (3.0.2)
  • builder (2.1.2)
  • bundler (1.0.15)
  • capistrano (2.6.0)
  • erubis (2.6.6)
  • exception_notification_rails3 (1.2.0)
  • highline (1.6.2)
  • i18n (0.5.0)
  • mail (2.2.19)
  • meta-tags (1.2.3 96ae3d9)
  • mime-types (1.16)
  • net-scp (1.0.4)
  • net-sftp (2.0.5)
  • net-ssh (2.1.4)
  • net-ssh-gateway (1.1.0)
  • pg (0.11.0)
  • polyglot (0.3.1)
  • rack (1.2.3)
  • rack-mount (0.6.14)
  • rack-test (0.5.7)
  • rails (3.0.9)
  • railties (3.0.9)
  • rake (0.8.7)
  • rdoc (3.6.1)
  • ruby-graphviz (1.0.0)
  • rubyzip (0.9.4)
  • safeeval (0.0.1)
  • sqlite3 (1.3.3)
  • sqlite3-ruby (1.3.3)
  • state_machine (1.0.1)
  • thor (0.14.6)
  • treetop (1.4.9)
  • tzinfo (0.3.28)
  • validates_email_format_of (1.4.7)
  • will_paginate (3.0.pre3 b1a5bee)
    $ ruby -v
    ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.02

dyba commented Jun 29, 2011

Ok, so you were using Ruby 1.8.7 p334 REE. I'll try that version of Ruby.

Getting this same issue with REE 1.8.7

I have the same issue in Ruby 1.9.2 p180. It doesn't happen in a fresh rails app, so it seems there's a gem somewhere that creating an object called Commands and causing rails plugin to fail. I will see if I can track down which gem it is.

I did a grep of my bundle for "Commands" and found that compass defines module Commands.

Rake 0.9.2 creates an object called "Commands":
./rake-0.9.2/lib/rake/dsl_definition.rb: Commands = Object.new.extend DSL

If I track down what in Rails 3.0.9 is calling Commands, it's /railties-3.0.9/lib/rails/commands/plugin.rb:279

When I debug plugin.rb, Commands is a "Object", not a "Module", so my guess is that the rake dsl_definition Commands is already defined and thus when Rails tries to turn it into a module, it barfs.

The fact that Compass also has a module called Commands may also be an issue, but I doubt it.

Yeah, the issue is clearly that Rake object, just figured that out myself.

The issue could be fixed by modifying /railties-3.0.9/lib/rails/commands/plugin.rb to place Commands inside another module, although I would consider this to be a bug in Rake as well.

In the meantime, using a version of Rake earlier than 1.9.2 (1.9.1 is fine) fixes the problem


dyba commented Jul 13, 2011

@mateomurphy, can you create a Rails app that has this issue? I can't recreate it.

simply including gem 'rake', '0.9.2' in a fresh rails app is enough to cause the issue for me


dyba commented Jul 14, 2011

@mateomurphy, I included gem 'rake', '0.9.2' in my rails app's Gemfile and ran rake -T with no problems. Again, pushing a sample app to Github would prove tremendously helpful rather than ping-ponging back and forth like this.

rake -T works fine, it's rails plugin install git://github.com/mislav/will_paginate.git that won't work with rake 0.9.2 specified in the gem file. Are you able to get the rails plugin to work?

I could push a sample app, but as I've said the only thing I need to do to a fresh rails app to reproduce the error is add that line to the gemfile.

I have the same problem as @mateomurphy. Trying to downgrade rake to 1.8.7 as I don't need it at the moment. Not fun.


dyba commented Jul 16, 2011

@phillipoertel, @mateomurphy, @MattRogish OK, I see the same thing too. I'm looking into it right now.

Cool, thanks!


dyba commented Jul 17, 2011

Ok, this works now. I'll send it to the Rails core team for approval.

rfc2822 commented Jul 22, 2011


@rfc2822 rfc2822 closed this Jul 22, 2011

@dyba thanks so much for this fix. What's the best way to get this change in Rails 3.0.x? Is there a Gemfile line that should be added to pull this via git or another route you'd suggest?

EDIT: I've just gone ahead and forked Rails myself and then just added your patch as per: http://bit.ly/pyGpjD as that's about the best way I've seen how to do this so far.

@ylluminate If you use rails 3.0.9- with rake 0.9.2, you should add include Rake::DSL to Rakefile just after require 'rake'.
Then add module Commands; end to script/rails just before require 'rails/commands', you will not get 'Commands is not a module (TypeError)' error message any more.


aaronchi commented Sep 3, 2011

What's going on with this issue? Still having problems in Rails 3.1 with this and rake 0.9.2

Dyba worked on a fix but it doesn't seem to have been applied, so I'm not sure why this is marked as closed

@aaronchi Rails 3.1.0 is fine with rake 0.9.2. It's the case of rails 3.0.9


aaronchi commented Sep 4, 2011

I just reproduced this on 3.1. Only works if I add module Commands; end to script/rails as described in another post

@tsechingho's post worked for me on Rails 3.0.10 and rake 0.9.2... thanks!

acconrad commented Sep 8, 2011

@tsechingho's post also worked for Rails 3.0.3 and Rake 0.9.2. Thanks again for the help!

ileitch commented Sep 18, 2011

Still a problem for me with 3.1 and rake 0.9.2.

Thanks @tsechingho it worked for me. Using rails 3.0.10 rake 0.9.2

sujal commented Oct 10, 2011

Still happening on 3.1.1 and rake 0.9.2 for me, as well. Adding the module Commands; end as indicated a few comments above fixed it for me. Based on other comments, I think this should be reopened for 3.1.1.


dyba commented Oct 10, 2011

What happened to my fix? Boo. I'll take care of this.

Did you try adding "bundle exec" before the rake command?

----- Reply message -----
From: "sujal" reply@reply.github.com
Date: Mon, Oct 10, 2011 10:24 am
Subject: [rails] "rails plugin" command doesn't work with rake 0.9 (#1866)
To: "Adam Conrad" acconrad@gmail.com

Still happening on 3.1.1 and rake 0.9.2 for me, as well. Adding the module Commands; end as indicated a few comments above fixed it for me. Based on other comments, I think this should be reopened for 3.1.1.

Reply to this email directly or view it on GitHub:
#1866 (comment)

dhyan commented Nov 3, 2011

@tsechingho -Thanks for the tips man..it worked...

tenderlove added a commit that referenced this issue Nov 16, 2011

Merge pull request #2122 from dyba/3-0-stable
Issue #1866: Changed Commands module to RailsCommands.

tenderlove added a commit that referenced this issue Nov 16, 2011

Changed Commands module to RailsCommands.
This is to avoid a conflict that occurs when you add Rake to
your Gemfile. There is a Commands Object in Rake that conflicts
with the Commands module in plugin.rb. See rails issue #1866.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment