jekyll serve throws 'no implicit conversion of Hash into Integer ' error
Asked Answered
B

5

5

I am following Michael Hartl's Learn Enough CSS course. My current folder layout is as follow:

- _layouts
- _site
index.html

where index.html is:

---
layout: test
---

and I have test.html in _layouts as:

Hello again, world.

Whenever I run jekyll serve, I get this error:

Error reading file /Users/pj/Documents/LETGD/repos/pohjie.github.io/_layouts/test.html: no implicit conversion of Hash into Integer 
Error reading file /Users/pj/Documents/LETGD/repos/pohjie.github.io/index.html: no implicit conversion of Hash into Integer 

Does anyone have any idea what's happening? I'm using M1 MacBook, not sure if that is a possible cause as I spent a lot of time install Ruby as well.

Thanks!

Bascule answered 9/2, 2021 at 5:47 Comment(3)
I don't see this code in your github repo, if you could commit it, it would help. In the meanwhile, can you add to your question the output of bundle exec jekyll build --trace.Motorcar
@BradWest Thanks for replying! It turns out I did not do gem install bundler, which is why I had issues with jekyll!Bascule
are u using a newer version of ruby? x=> 3?Thermit
R
6

While downgrading certainly works, it may be pretty annoying and (depending on where you need this) problematic. If you just want a simple workaround, you can make use of the fact that jekyll build still works with Ruby 3 and just serve the page separately:

bundler exec jekyll build && bash -c 'cd _site && python -m http.server 3000'

The only downside of this is that you lose the automatic reload. If you change anything, you need to restart jekyll. But you can run this in a Ruby 3 environment without fiddling with the environment itself.

Racial answered 4/9, 2022 at 12:9 Comment(0)
V
3

Downgrading to Ruby 2.7 is an option (as others have said) which I didn't feel like doing, so I did this instead:

  1. Apply the patch to pathutil

    From Liviu Stefan's answer:

    Ruby 3.0 deprecated using the last argument as keyword parameters. A double splat ** has to be added before the variable for the behavior to be supported.

    Here's how I applied the patch locally:

    sudo sed -i.bak 's/, kwd/, **kwd/' $(gem which pathutil)
    
  2. After that I got another error:

    /var/lib/gems/3.0.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve/servlet.rb:3:in `require': cannot load such file -- webrick (LoadError)
    

    Which I fixed by running (from bundle exec jekyll serve: cannot load such file):

    bundle add webrick
    
Viminal answered 30/9, 2022 at 13:48 Comment(1)
This is what I was expecting to read. What is the real problem and some compatible solution. Therefore, I got app running. I noted that code frequency in Jekyll's repo in Github is almost inexistent, what says much about this error. Thank you.Misinform
M
1

Quoting from this source:-

Github-Pages uses Jekyll 3.9, which isn’t compatible with Ruby 3. Downgrading to Ruby 2.7 should avoid the problem.

This worked for me.

Monagan answered 18/5, 2021 at 5:45 Comment(1)
Similarly, short fix just downgrade.Thermit
K
1

To stay with Ruby 3 or later, you can specify this Ruby 3 compatible update in your Gemfile:

gem "pathutil", github: "sdogruyol/pathutil", ref: '6ab144a7706c2bc5fa0dfdfa498e94ff66e944c6'

A full Gemfile would then look something like below. (I've also included webrick here as it's a separate workaround needed for Ruby 3 and later).

source "https://rubygems.org"

# This will help ensure the proper Jekyll version is running.
gem "jekyll"
gem "webrick"
gem "pathutil", github: "sdogruyol/pathutil", ref: '6ab144a7706c2bc5fa0dfdfa498e94ff66e944c6'

# if you want jekyll plugins
# group :jekyll_plugins do
  # gem 'jekyll-paginate'
  # (etc)
# end

Then run bundle update and bundle exec jekyll serve --incremental as usual.

Kieffer answered 18/12, 2023 at 14:21 Comment(0)
O
0

Ruby 3.0 deprecated using the last argument as keyword parameters. A double splat ** has to be added before the variable for the behavior to be supported.

It's fairly straightforward to amend locally; the relevant patch is found: here

Which needs to be applid to:

/home/<your_user_name>/gems/gems/pathutil-0.16.2/lib/pathutil.rb

Opinion answered 24/5, 2022 at 8:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.