jekyll / jekyll

:globe_with_meridians: Jekyll is a blog-aware static site generator in Ruby

Home Page:https://jekyllrb.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Jekyll serve fails on Ruby 3.0

argilo opened this issue · comments

My Environment

Software Version(s)
Operating System Ubuntu 20.04
Ruby 3.0.0
jekyll 4.2.0
github-pages No

Expected Behaviour

bundle exec jekyll serve runs on Ruby 3.0.

Current Behavior

bundle exec jekyll serve fails with the following stack trace:

/home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve/servlet.rb:3:in `require': cannot load such file -- webrick (LoadError)
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve/servlet.rb:3:in `<top (required)>'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:179:in `require_relative'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:179:in `setup'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:100:in `process'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `block in process_with_graceful_fail'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `each'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `process_with_graceful_fail'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:86:in `block (2 levels) in init_with_program'
	from /home/argilo/.gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `block in execute'
	from /home/argilo/.gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `each'
	from /home/argilo/.gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `execute'
	from /home/argilo/.gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/program.rb:44:in `go'
	from /home/argilo/.gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary.rb:21:in `program'
	from /home/argilo/.gem/ruby/3.0.0/gems/jekyll-4.2.0/exe/jekyll:15:in `<top (required)>'
	from /home/argilo/.gem/ruby/3.0.0/bin/jekyll:23:in `load'
	from /home/argilo/.gem/ruby/3.0.0/bin/jekyll:23:in `<top (required)>'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `load'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `kernel_load'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:28:in `run'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/cli.rb:497:in `exec'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/cli.rb:30:in `dispatch'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/cli.rb:24:in `start'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/bundler-2.2.3/libexec/bundle:49:in `block in <top (required)>'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/3.0.0/bundler/friendly_errors.rb:130:in `with_friendly_errors'
	from /home/argilo/.rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/bundler-2.2.3/libexec/bundle:37:in `<top (required)>'
	from /home/argilo/.rubies/ruby-3.0.0/bin/bundle:23:in `load'
	from /home/argilo/.rubies/ruby-3.0.0/bin/bundle:23:in `<main>'

This happens because webrick is no longer a bundled gem in Ruby 3.0. From https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/:

The following libraries are no longer bundled gems or standard libraries. Install the corresponding gems to use these features.

  • sdbm
  • webrick
  • net-telnet
  • xmlrpc

Adding gem "webrick" to my Gemfile solves the problem, but Jekyll should include it in its gemspec.

I think you want bundle add webrick.

+1 for the issue with webrick, I faced a similar problem when running jekyll serve in a different context than the one described here.

@argilo Thanks, you really saved my day.

@argilo you're a lifesaver thank you so much!

Thanks, adding webrick worked for me.

Thank you @argilo, $bundle add webrick works!

Thank you @argilo!

webrick did the job for me too - thanks @argilo.

Big thanks from me as well @argilo
You've allowed me to stop working before midnight

I don't have experience with Ruby dependency management. Does adding the webrick gem definition to a Jekyll site's Gemfile cause issues in ruby < 3.0? Is the optimal approach to address this issue documentation that users on ruby 3.0+ should use bundle add webrick before they use jekyll serve?

Does adding the webrick gem definition to a Jekyll site's Gemfile cause issues in ruby < 3.0?

No, it does not.

Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/.
Could not find gem 'webdrick x86_64-linux' in any of the gem sources listed in
your Gemfile.

@joaroque It looks like you've got a typo in the gem name. It should be "webrick".

Thank you @argilo

commented

Thank you @argilo, $bundle add webrick works!

This worked for me (gem webrick does not work). Thanks!

When I use the bundle add webrick line I get Could not find command "add". I made sure that I am running the latest bundler.

Solution: Add 'webrick' to the gemfile as a stand alone ...

gem 'webrick', '>=1.7.0'

Note. Maximum ruby = 2.7.1 per https://pages.github.com/versions/ as of 03/24/21
But, this works w ver 3.0.0
bundle update ... check!
jekyll serve --watch --baseurl "" --port 4000 -o ... check!
Thx!

Still the same problem. Thank you @argilo!

After adding webrick, the error 'listen-3.2.1 requires ruby version ~> 2.2, >= 2.2.7, which is incompatible with the current version, ruby 3.0.0p0' raised...

Update: bundle update fix it

bundle add webrick

worked perfectly thanks! @argilo

bundle add webrick works neatly.

Thanks @argilo

Please note, as @persistz suggested, after

bundle add webrick

it is advisable to run

bundle update

to make sure other dependencies are updated to work with the new Ruby 3.0 version.

I think you want bundle add webrick.

Thanks, that worked :)

I think you want bundle add webrick.

Thanks, that saved my day!

commented

Both bundle exec jekyll serve and jekyll s work for me ; despite, I'm getting a incompatible library version for http_parser.rb when appending the --livereload flag to the serve command, hence live reload is not active. Working with Ruby 3.0.0 in the MacBook Pro M1 with ARM64 processor. Here's the log:

/Users/xx/.local/share/gem/ruby/3.0.0/gems/http_parser.rb-0.6.0/lib/http_parser.rb:2:in `require': incompatible library version - /Users/xx/.local/share/gem/ruby/3.0.0/gems/http_parser.rb-0.6.0/lib/ruby_http_parser.bundle (LoadError)
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/http_parser.rb-0.6.0/lib/http_parser.rb:2:in `<top (required)>'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/http_parser.rb-0.6.0/lib/http/parser.rb:1:in `require'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/http_parser.rb-0.6.0/lib/http/parser.rb:1:in `<top (required)>'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/em-websocket-0.5.2/lib/em-websocket/handshake.rb:1:in `require'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/em-websocket-0.5.2/lib/em-websocket/handshake.rb:1:in `<top (required)>'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/em-websocket-0.5.2/lib/em-websocket.rb:15:in `require'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/em-websocket-0.5.2/lib/em-websocket.rb:15:in `block in <top (required)>'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/em-websocket-0.5.2/lib/em-websocket.rb:14:in `each'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/em-websocket-0.5.2/lib/em-websocket.rb:14:in `<top (required)>'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve/live_reload_reactor.rb:3:in `require'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve/live_reload_reactor.rb:3:in `<top (required)>'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:143:in `require_relative'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:143:in `register_reload_hooks'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:98:in `process'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `block in process_with_graceful_fail'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `each'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/command.rb:91:in `process_with_graceful_fail'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/lib/jekyll/commands/serve.rb:86:in `block (2 levels) in init_with_program'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `block in execute'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `each'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/command.rb:221:in `execute'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary/program.rb:44:in `go'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/mercenary-0.4.0/lib/mercenary.rb:21:in `program'
        from /Users/xx/.local/share/gem/ruby/3.0.0/gems/jekyll-4.2.0/exe/jekyll:15:in `<top (required)>'
        from /Users/xx/.rbenv/versions/3.0.0/bin/jekyll:23:in `load'
        from /Users/xx/.rbenv/versions/3.0.0/bin/jekyll:23:in `<main>'

Thank you.
bundle add webrick works!

Just installed Jekyll via Homebrew, and this is still an issue for the MacOS installation.
But
bundle add webrick
fixed the problem!
Thank you.

Good! I think version is best new led to the problem.

@argilo Thank you so much!

Thank you so much for the fix. Worked great!

WORKS! Thanks!

I have the same problem on Mac, but when I am entering bundle add webrick I get the line Could not locate Gemfile Anyone an idea? I am pretty new to ruby and jekyll.

I have the same problem on Mac, but when I am entering bundle add webrick I get the line Could not locate Gemfile Anyone an idea? I am pretty new to ruby and jekyll.

First gem install webrick
than bundle add webrick

bundle exec jekyll serve works :)

@argilo Thank you so much! it's working 💖

add webrick
image

I think you want bundle add webrick.

thanks,u save my day

Adding bundle install worked for me.
Thanks

Thanks!

bundle add webrick worked for me, though I have no idea what changed to require this.

I have no idea what changed to require this.

It's necessary because Jekyll depends on WEBrick, and WEBrick is no longer a bundled gem in Ruby 3.0: https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/

I fixed this by adding WEBrick to Jekyll's gemspec in #8524, but it's been almost a year and it has yet to be included in a Jekyll release. 😢 The workaround is to manually add webrick to your Gemfile.

Thank You, it worked for me

Please make a release for this...

Jekyll should work (even without bundler) on all current Ruby versions!

Thanks, my environment:

image


  1. Change your project's Gemfile.

  2. Run sudo bundle install in your project's folder again.

    then, it works! 😎

image

I have no idea what changed to require this.

It's necessary because Jekyll depends on WEBrick, and WEBrick is no longer a bundled gem in Ruby 3.0: https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/

I fixed this by adding WEBrick to Jekyll's gemspec in #8524, but it's been almost a year and it has yet to be included in a Jekyll release. 😢 The workaround is to manually add webrick to your Gemfile.

Can you explain how to do that?

The workaround is to manually add webrick to your Gemfile.

Can you explain how to do that?

Open a command-line prompt, move into your Jekyll source directory and then run bundle add webrick.

The workaround is to manually add webrick to your Gemfile.

Can you explain how to do that?

Open a command-line prompt, move into your Jekyll source directory and then run bundle add webrick.

Thanks.

I was struggling because I didn't do the "move into your Jekyll source directory" part.

Thank you @argilo, $bundle add webrick works!

Pretty dope that this is still an issue.

commented

Is there something about this issue that makes it harder to fix than it seems? Seems like a one liner?

The fix was indeed a one-liner. The trouble is that there has not been a feature release in more than a year. There was a bug fix release (4.2.1) in September, but it did not include #8524.

commented

It would appear that it is still happening. Thankfully @argilo 's fix works still.

Still happening, but thanks @argilo this fix save me

Issue happened for me as well, but this fix worked. Thank you @argilo !

commented

thank you!@argilo

You saved my day thank you @argilo !

commented

Errors are
bundler: failed to load command: jekyll
cannot load such file -- webrick (LoadError)

bundle add webrick saved the day.
Thank you so much!

Thanks a lot @argilo !!!!

commented

Thanks! @argilo

Wow! Already lost almost two hours because of that. For most of it I actually thought it was a problem with docker (I'm using docker-compose) since building was very long... at some point I left the container running long enough for the building to end with this error, which led me here! I just added gem "webrick" as you suggested, run docker compose down then docker compose up again and voilà! Works pretty fine, thanks sooooo much @argilo !!

Why is this issue closed? Dozens of comments in the lines of "fixed! works for me, thanks!" does not mean a problem is resolved.

My environment is a WSL2 Ubuntu LTS (meaning Ubuntu 22.04 running on Windows 10 or 11).

I used the bundler approach and I don't use the root account, so my step by step was this:

$ sudo apt-get install ruby-full build-essential zlib1g-dev #this is the only time sudo should be needed
$ gem install --user-install bundler
$ mkdir user.github.io
$ cd user.github.io/
$ bundle init
$ bundle add jekyll

$GEM_HOME on a vanilla install is an empty string so this is mandatory, or bundler will invoke sudo:

$ bundle config set --local path 'vendor/bundle'

This command erased my existing Gemfile and .gitignore, I regret following the site's instructions:

$ bundle exec jekyll new --force --skip-bundle .
$ bundle install
$ bundle exec jekyll serve

That last command will fail and lead me to one and a half hour learning about ruby, gems, bundler and ultimately to this issue.

There's a missing step in the instructions somewhere before bundle install which is:

$ bundle add webrick

The default version in this particular environment is currently Jekyll 4.2.2 which does not include webrick in the jekyll.gemspec and therefore it doesn't get added to Gemfile.

#8524 did not fix this issue so I don't understand why it's closed.

This issue will keep happening for everyone until they reach a version where this is fixed, which will take a lot of time.

The very least would be a document notice, but that has been proposed but not implemented.

#8524 did not fix this issue so I don't understand why it's closed.

That pull request did fix the issue, however it was only merged into the master branch (which has not made it into a release yet) and was not backported into a 4.2.x bug-fix release.

Given that Ruby 3.0 was released 1.5 years ago and a large number of people are running into this issue (as evidenced by the number of comments on this issue), I think the fix should be added to a 4.2.3 release. Perhaps @ashmaroli could arrange that?

I think we should just fast-track the release of 4.3.0 instead. /cc @jekyll/core

That works. As long as the newest available release has the fix, the problem should be resolved for most users.

@ashmaroli Release 4.3.0 when ready. Happy to review release notes at your convenience!

I still argue for adding webrick to all affected versions in jekyll.gemspec. The reason I didn't made a pull request for that in each of the affected branches is I still can't get rbenv to work (I'm new to Ruby) so I'm not confident I'm patching the right versions.

I am almost sure that many people will keep using 4.2.x for some time, regardless of the website telling them to upgrade. Lots of people, lots of different OSs and possible environments.

bundle add webrick worked for me. Thanks argilo.

This has been fixed, but do I understand correctly that the fix is not yet in any released version of Jekyll?

That's correct. The fix was merged into the master branch in January of 2021, but has yet to make it into any release.

webrick worked perfectly. thanks @argilo

Hi, I am not familiar with ruby :( I have just installed Jekyll like described https://jekyllrb.com/docs/installation/macos/
and I have the mentioned problem with jekyll server. Where should I run $ bundle add webrick?

EDIT:
I have tryied to install gem install --user-install webrick but it installed for ruby version 3.1.0 folder, where by version of ruby is 3.1.2.

@valor-motao And may I ask what role does shopify-cli have in a Jekyll site?

@argilo I have the same problem with Ruby 3.2.1 on macOS. Adding webrick to Gemfile doesn't help. Jekyll 3.6.3. Upgrading to Jekyl 4.3.2 solved the problem.

I think you want bundle add webrick.

gigachad

I think you want bundle add webrick.

It works for me!

I added webrick.

Still getting the following error:

Jekyll 4.3.2 Please append --trace to the serve command
for any additional information or backtrace.

Going to take a break before I mess anything up further. Posting if anyone has a solution.

If/when I figure out the issue I'll reply to this comment.

Going for a walk. Thanks!

I think you want bundle add webrick.

Worked like a charm. Thank you @argilo!

Mine threw the error but said JSON instead of webrick. i did bundle add json instead and things seem to be working great. command is still processing though.

Mine threw the error but said JSON instead of webrick. i did bundle add json instead and things seem to be working great. command is still processing though.

I can confirm, I had the same issue and bundle add json fixed the problem.