I've tried to find some solution for this, but I really couldn't find anything related with the errors that is appearing to me when I run the rails command:
rails generate model Book title:string summary:text isbn:string
/home/vmu/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated
/home/vmu/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated
/home/vmu/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0.1/lib/active_support/core_ext/numeric/conversions.rb:138: warning: constant ::Fixnum is deprecated
Running via Spring preloader in process 3579
Expected string default value for '--jbuilder'; got true (boolean)
invoke active_record
identical db/migrate/20170104114702_create_books.rb
identical app/models/book.rb
invoke test_unit
identical test/models/book_test.rb
identical test/fixtures/books.yml
Anyone know what may be causing these errors?
This warnings appear because you are using ruby 2.4.0.
This version introduced this change: Unify Fixnum and Bignum into Integer
See here for the announcement: https://www.ruby-lang.org/en/news/2016/12/25/ruby-2-4-0-released/
The warnings come from the activesupport gem which is part of rails and will be fixed in an upcoming release.
For now you can just ignore those warnings.
Update: Rails 5.0.2 has been released, which gets rid of the warnings.
I fixed mine by updating rails
bundle update rails
I assume you're using Rails 5? Check out this link (towards the bottom). Looks like these warnings will go away with release #27458.
If these deprecation warnings in active support are the only warnings you are seeing, you can surpress them by passing a RUBYOPT bash variable with the -W0 option which will silence.
so instead of rails server
try: RUBYOPT="-W0" rails server or RUBYOPT="-W0" bin/rails server
In rails 5.0 you may want to get in the habit of using bin/rails not just rails, since that's the global rails version which may or may not be the same as your local rails version.
I fixed this updating therubyracer gem from version '0.12.2' to '0.12.3'
Related
with a recent upgrade to rails 7.0.2 from rails 5.2, when ever i start a rails console or a rails server on dev mode i see these warnings
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/digest-3.1.0/lib/digest.rb:20: warning: already initialized constant Digest::REQUIRE_MUTEX
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/digest.rb:6: warning: previous definition of REQUIRE_MUTEX was here
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/net/protocol.rb:66: warning: already initialized constant Net::ProtocRetryError
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/net-protocol-0.1.3/lib/net/protocol.rb:68: warning: previous definition of ProtocRetryError was here
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/net/protocol.rb:206: warning: already initialized constant Net::BufferedIO::BUFSIZE
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/net-protocol-0.1.3/lib/net/protocol.rb:208: warning: previous definition of BUFSIZE was here
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/net/protocol.rb:503: warning: already initialized constant Net::NetPrivate::Socket
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/net-protocol-0.1.3/lib/net/protocol.rb:504: warning: previous definition of Socket was here
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/apipie-rails-0.7.0/lib/apipie/extractor/recorder.rb:163: warning: Skipping set of ruby2_keywords flag for process (method accepts keywords or method
For what's its worth the warnings are not present when the application is on Rails 7.0 but only appear when the application is upgraded to Rails 7.0.2
I upgraded rails as per the guide
5.2 -> 6.0 -> 6.1 -> 7.0 -> 7.0.2
May be i missed something, anyways I could fix these? probably these would go away with a ruby / rails subsequent upgrade?
Thanks.
Rails 7.0.1 added some gem dependencies for standard lib stuff that would get removed in ruby 3.0. This unfortunately causes issue with ruby 2.7.6. You can get around this in several ways. Upgrading ruby will also upgrade bundler which fixes the issue. Upgrading bundler without ruby also works but I don't recommend it (better to point to the system version). A more conservative workaround is find the gems that are causing issues and list them on the top of your Gemfile. In my case I had to make sure that the gem version was the same as the default ruby gem version. For example, I had to make the Gemfile have gem "uri", "0.10.0". A good way to debug what is causing these is put this at the top of your Gemfile:
Warning.module_eval do
alias_method :original_warn, :warn
def warn(msg)
if msg.match?(/already initialized constant/)
raise msg
else
original_warn(msg)
end
end
end
That way you get a stacktrace of the places that are requiring stdlib files that also have a conflicting rubygem.
It looks like these are all constants defined in dependency code gems. Running bundle clean --force or updating dependencies with bundle update and then running the bundle clean --force has worked for some when experiencing this issue.
Did anyone resolve this issue with Ruby 2.7.0?
I used rbenv and installed Ruby v2.7.0 and then created a Rails project using Rails v6.0.2.1.
Currently, by running one of
rails s
rails s -u puma
rails s -u webrick
the server is up and the site is served but in the Console log I see two warning messages:
local:~/rcode/rb27$ rails s
=> Booting Puma
=> Rails 6.0.2.1 application starting in development
=> Run `rails server --help` for more startup options
.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/static.rb:110: warning: The called method `initialize' is defined here
Puma starting in single mode...
* Version 4.3.1 (ruby 2.7.0-p0), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
So, the warning messages are:
**.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call**
**.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/static.rb:110: warning: The called method `initialize' is defined here**
I saw this link and there are some suggestion to switch of warnings like "If you want to disable the deprecation warnings, please use a command-line argument -W:no-deprecated or add Warning[:deprecated] = false to your code." but I was thinking on little bit better solution/fix for actionpack v6.0.2.1
To suppress warnings like:
warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
For now, simply prefix/pass the RUBYOPT environment variable to your rails commands:
RUBYOPT='-W:no-deprecated -W:no-experimental' rails server
or
RUBYOPT='-W:no-deprecated -W:no-experimental' rails db:migrate
This may not work with earlier versions of ruby.
For backward compatibility with earlier versions of ruby prefix it with RUBYOPT='-W0' instead.
example:
RUBYOPT='-W0' bundle exec rspec
If you don't want to prefix this each time you run a command, then simply add this to the last line of your .zshrc or .bashrc (whatever you're using):
export RUBYOPT='-W:no-deprecated -W:no-experimental'
or
export RUBYOPT='-W0'
Also see last point of the notes here:
https://rubyreferences.github.io/rubychanges/2.7.html#warning-and-
Update to Rails 6.0.3, they fixed the warnings.
If you still get warnings, it's other libraries (see if there are fixed versions or submit a patch) or your own code (how to fix it).
Obviously it will take some time to for ruby team to remove all this warning in next ruby version. For now the command in your terminal
`RUBYOPT='-W:no-deprecated' rails s`
on my basic, plain new rails 6.0.2.1 && ruby 2.7.0 project remove these two warnings lines above in a question.
Also, with command
RUBYOPT='-W:no-experimental' rails s
you will hide warnings about experimental features.
You can combine these two in one command like:
RUBYOPT='-W:no-deprecated -W:no-experimental' rails s
However, I tried these commands inside my old project built with rails 5.2 and ruby 2.6.4 later upgraded to rails 6.0.1 and they didn't worked well on for all warnings messages I got from different rails Active* modules and ruby gems.
Probably we will need some time for upgrading code and gems for new latest stuff.
I have searched documentation to this error that I have never seen before in working with Ruby on Rails. I just got a new MacBook and I installed Rails 4.2 and Ruby 2.4 and when I attempt to run rails server, I get this error:
.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/thread_safe-0.3.5/lib/thread_safe/cache.rb:155: warning: constant ::Fixnum is deprecated
How do I eliminate this error that is keeping me from starting up the Rails server?
Im not sure if that's the issue, since what you are seeing is just a warning. That warning appears because you are using ruby 2.4.0.
This version introduced this change: Unify Fixnum and Bignum into Integer
See here for the announcement: https://www.ruby-lang.org/en/news/2016/12/25/ruby-2-4-0-released/Z
The warnings come from the activesupport gem which is part of rails, and they will fix it soon.
Try downgrading your Ruby Version to 2.1 and try again.
Source
I am using Rails 2.3.11. I am getting a lot of deprecation warning like
DEPRECATION WARNING: Rake tasks in vendor/plugins/delayed_job/tasks,
vendor/plugins/fckeditor/tasks,
vendor/plugins/jrails/tasks,
vendor/plugins/query_reviewer/tasks,
vendor/plugins/thinking-sphinx/tasks,
vendor/plugins/tiny_mce/tasks, vendor/plugins/tolk/tasks,
and vendor/plugins/xss_terminate/tasks are deprecated.
Use lib/tasks instead. (called from /usr/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/tasks/rails.rb:10)
Give suggestions to avoid these warnings
Move tasks into lib/tasks…
No, actually, start using bundler. If an upgrade to Rails 3.x is too much work, at least move over to bundler and move all those dependencies into your Gemfile. It works fine with Rails 2.3.
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
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.
I'm afraid the easier solution is running this command instead of rake db:migrate
bundle exec rake db:migrate
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
bundle exec bash works for me
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
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.
I had a .bundler folder on my root directory which was conflicting. Removing it did it for me.
rm -rf ~/.bundler
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
Just got such error because of deleted .rvmrc
So please make sure you running rake in correct environment ;)
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
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.
This can happen when you have the rake gem installed in both your repo's rvm gemset and the global one.
Update to latest Rails minor version.
So if you are at 4.2, update => 4.2.latest.