Rails 3.0 & Ruby 1.9.2rc: Rake commands return 'already initialized constant' & stack level too deep errors. Any ideas
Asked Answered
H

13

25

I'm trying to run Rails 3 beta 4 & Ruby 1.9.2rc on Ubuntu 10.04. It worked initially, but after doing my first bundle install/package, I now get the following errors in all rails projects. Even a basic 'rails new testproject' followed by a rake brings up the error messages.

In short, I'm stumped. Any help regarding what could be causing this would be very appreciated.

The only thing I noticed - which may or may not be relevant - is that the directory in the ~/.bundle files is ruby/1.9.1. 1.9.1 is not installed on my machine - only 1.9.2rc. ruby -v brings back 1.9.2

(in /home/john/Websites/sandbox/testerino)
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:32: warning: already initialized constant RAKEVERSION
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake/alt_system.rb:32: warning: already initialized constant WINDOWS
WARNING: Possible conflict with Rake extension: String#ext already exists
WARNING: Possible conflict with Rake extension: String#pathmap already exists
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:404: warning: already initialized constant EMPTY_TASK_ARGS
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:452: warning: already initialized constant EMPTY
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:960: warning: already initialized constant RUBY_EXT
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:964: warning: already initialized constant RUBY
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1033: warning: already initialized constant LN_SUPPORTED
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1242: warning: already initialized constant ARRAY_METHODS
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1245: warning: already initialized constant MUST_DEFINE
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1249: warning: already initialized constant MUST_NOT_DEFINE
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1253: warning: already initialized constant SPECIAL_RETURN
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1259: warning: already initialized constant DELEGATING_METHODS
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1569: warning: already initialized constant DEFAULT_IGNORE_PATTERNS
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1575: warning: already initialized constant DEFAULT_IGNORE_PROCS
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1612: warning: already initialized constant FileList
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1638: warning: already initialized constant EARLY
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1968: warning: already initialized constant DEFAULT_RAKEFILES
rake aborted!
stack level too deep
Hierocracy answered 6/7, 2010 at 4:28 Comment(1)
Happens on all projects, including a bare install.Hierocracy
S
24

I'm afraid the easier solution is running this command instead of rake db:migrate

bundle exec rake db:migrate
Squeegee answered 22/8, 2011 at 13:47 Comment(2)
Yeah - that might actually be better, since your environment isn't modified.Maximalist
It was suggested by a friend of mine, Pratik Naik (stackoverflow.com/users/639946/pratik-naik) who also happens to be in rails core team. Don't -1 my post because of that, I was just spreading knowledge. :)Squeegee
M
31

I've been running into this issue too. It doesn't seem to be related to the specific versions of rails or ruby you mention, which are different than the ones I'm using (Rails 2.3.8, Rake 0.8.7, Ruby 1.9.1p378). It seems to be related to bundler and rake not working well together.

A resolution that worked for me is mentioned at the bottom of this lighthouse ticket. Here is the short version:

  • Run "bundle exec bash"; see if rake works now - if it does,
  • Make sure that the bash environments, before and after, are the same by consulting the env command and modifying ~/.bashrc or ~/.bash_profile accordingly.

Once you do this, you mess up bundler a little bit. At that point you have to clear RUBYOPT in order to run the bundle command:

RUBYOPT= bundle install --relock

EDIT:

Thinking about it a little more, I'm not sure this is necessarily the best way to address this particular issue. You might give Hiral Desai's tip and some other answers a try before resorting to this approach, since this one changes the environment.

Maximalist answered 19/7, 2010 at 0:14 Comment(1)
I had a similar issue executing any rake task in my Rails app. It went away after running bundle exec bash, but I have to re-run bundle exec bash if I open a new tab in my terminal.Machuca
S
24

I'm afraid the easier solution is running this command instead of rake db:migrate

bundle exec rake db:migrate
Squeegee answered 22/8, 2011 at 13:47 Comment(2)
Yeah - that might actually be better, since your environment isn't modified.Maximalist
It was suggested by a friend of mine, Pratik Naik (stackoverflow.com/users/639946/pratik-naik) who also happens to be in rails core team. Don't -1 my post because of that, I was just spreading knowledge. :)Squeegee
L
4

As per the previous message from Eric W. the RUBYOPT environment variable is set. If you want to exit the new bash shell that is opened by "bundle exec bash" then just copy the RUBYOPT environment line, exit the shell then type "export RUBYOPT='THE ARGS THAT YOU COPIED FROM THE PREVIOUS ENVIRONMENT'

Note: this works with ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0] , Rails 3.0.7, gem 1.8.0 and Rake 0.8.7

Ludvig answered 5/5, 2011 at 21:36 Comment(0)
H
4

bundle exec bash works for me

Harlie answered 30/8, 2011 at 15:48 Comment(0)
S
3

I was able to solve this issue by downgrading my rubygem install from 1.8.10 to 1.7.2.

gem update --system 1.7.2
Semiquaver answered 21/10, 2011 at 16:55 Comment(1)
If you have rvm: rvm install rubygems 1.7.2Maudemaudie
C
1

Looks like a strange recursive require.

Did you try uninstalling all versions of rake and reinstalling it? There is a bug in 1.9.2rc affecting gem loading, so that might be it? I didn't look closely into it as many people are already following it closely...

Note: The 1.9.1 is the API version, so it is correct.

Cowbell answered 6/7, 2010 at 4:37 Comment(0)
R
0

I had a .bundler folder on my root directory which was conflicting. Removing it did it for me.

rm -rf ~/.bundler
Ronald answered 18/8, 2011 at 21:25 Comment(0)
O
0

I've been running into this issue too after updating rubygem (1.8.10) and bundler (1.0.18)

I solved updating rake to 0.9.2

Octant answered 1/9, 2011 at 9:9 Comment(0)
S
0

Just got such error because of deleted .rvmrc

So please make sure you running rake in correct environment ;)

Scrape answered 13/9, 2011 at 2:50 Comment(0)
M
0

If you have RVM installed, this issue can start to occur once you update rubygems to 1.8.15. The issue was that I had rake installed in the global gemset and my project's gemset. The solution was to have only one installation of rake. To delete it from the project gemset: 1. cd to the project 2. gem uninstall rake

Maudemaudie answered 26/1, 2012 at 18:22 Comment(0)
E
0

Another possible solution is given at http://rubyist-journal.com/2011/07/29/howto-fix-rake-0-9-2-to-work-with-ruby-1-9-2-under-rvm/

It seems to boil down to having the same rake gem installed both in your user gem directory and system-wide. Removing either one fixes the issue.

Edlin answered 21/2, 2012 at 7:55 Comment(0)
A
0

This can happen when you have the rake gem installed in both your repo's rvm gemset and the global one.

Astrodynamics answered 7/6, 2013 at 17:47 Comment(0)
B
0

Update to latest Rails minor version. So if you are at 4.2, update => 4.2.latest.

Burrussburry answered 15/9, 2017 at 10:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.