33

I have a project I'm trying to use ruby 3 (previously running with 2.7.2), but couldn't accomplish it.

After updated my gemfile with the ruby version and ran bundle, I'm receiving this error when trying to access rails c:

/home/rwehresmann/.rvm/gems/ruby-3.0.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': cannot load such file -- webrick/httputils (LoadError)

I already tried to add webrick gem to see what happens, and the result is that rails c get stuck.

Here is my gemfile:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.0.0'

gem 'rails', '~> 6.0.1'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', ">= 4.3.3"

gem 'aws-sdk-s3', '~> 1'
gem 'http', '~> 4.3.0'
gem 'redis', '~> 4.1.3'
gem 'jwt', '~> 2.2.1'
gem 'pundit', '~> 2.1.0'
gem 'blueprinter', '~> 0.23.0'
gem 'money-rails', '~> 1.13.3'
gem 'dry-struct', '~> 1.3.0'
gem 'sidekiq', '~> 6.0.5'
gem 'sidekiq-scheduler', '~> 3.0.1'
gem 'friendly_id', '~> 5.2.4'
gem 'holidays', '~> 8.4.1'
gem 'administrate', '~> 0.14.0'
gem 'administrate-field-enum', '~> 0.0.9'
gem 'pg_search', '~> 2.3.2'
gem 'ransack', '~> 2.3.2'
gem 'administrate-field-active_storage', '0.3.4'
gem 'image_processing', '~> 1.2'
gem 'rolify', '~> 5.3.0'
gem 'active_storage_validations', '~> 0.8.7'
gem 'audited', '~> 4.9'
gem 'slack-ruby-client', '~> 0.15.0'
gem 'inky-rb', require: 'inky'
# Stylesheet inlining for email
gem 'premailer-rails'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
gem 'rack-cors'

group :development, :test do
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'rspec-rails', '~> 3.8.3'
  gem 'factory_bot_rails', '~> 5.1.1'
  gem 'capybara', '~> 3.31.0'
end

group :development do
  gem 'listen', '~> 3.4'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  gem 'letter_opener'
end

group :test do
  gem 'shoulda-matchers', '~> 4.2.0'
  gem 'webmock', '~> 3.8.2'
end

Any suggestions?

rwehresmann
  • 1,108
  • 2
  • 11
  • 27
  • You have `spring` in your gemfile, usually hanging consoles and servers are related to that. Try adding the webrick gem back into your gemfile, do a bundle install, and then run `bin/spring stop`. Then try re-running the console. Let me know if that works for you and I'll add it as an answer. – taylorthurlow Jan 07 '21 at 18:45
  • 3
    You've already resolved the title of this question and original error: [**`webrick` was removed from the standard library** in ruby 3](https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/). So yes, you need to install it as a gem. – Tom Lord Jan 07 '21 at 19:08
  • As for why running rails "gets stuck", I don't know, you haven't provided any further context. As suggested above, try restarting it fully. If it's still failing, check for any log message, and post all information you have available. – Tom Lord Jan 07 '21 at 19:09
  • @taylorthurlow it worked. However, I need to repeat this "stop process" every time I quit the console. Weird. – rwehresmann Jan 07 '21 at 23:36
  • @TomLord no log is provided. It just gets stuck and I need to close and reopen my terminal. Spring issues, like @taylorthurlow mentioned above. About webrick, it looks like is used with bootsnap gem, however, if I `rails new` a project the default gemfile includes bootsnap and it works perfectly without adding webrick in my gemfile. – rwehresmann Jan 07 '21 at 23:44
  • @rwehresmann I've added the solution as an answer, if you don't mind accepting it. As I note in the answer, I'd suggest reading up on Spring and what might cause it to do that sort of thing, and if you can't figure it out then opening a new question here on SO would be the next step. – taylorthurlow Jan 08 '21 at 00:15

2 Answers2

44

Try:

bundle add webrick

Adding gem "webrick" to Gemfile solves the problem.

Milovan Tomašević
  • 6,823
  • 1
  • 50
  • 42
40

You have spring in your gemfile, usually hanging consoles and servers are related to that. The webrick gem was removed from the standard library in Ruby 3, so that's why it needs to be included in your Gemfile.

Add webrick to your Gemfile, do a bundle install, and then stop the background spring server with bin/spring stop. Then re-run the server.

Your best bet on solving issues with spring would be to head over and read about the gem on the GitHub project page, or opening a new question here on SO.

taylorthurlow
  • 2,953
  • 3
  • 28
  • 42
  • 6
    It might be good to check which gem is relying on webrick instead of adding it as an additional dependency to the project. Looking at the gemfile in the original question it seems likely that the aws-sdk-s3 gem is the culprit, so updating that gem, if possible, may be a better solution. See [the aws-sdk-s3 commit that removed their webrick dependency](https://github.com/aws/aws-sdk-ruby/commit/87555162e4871eecdd38d3c5f5a1653e3ec88a02) – ordinathorreur Jan 12 '21 at 11:15