4

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!

pohjie
  • 51
  • 1
  • 6
  • 1
    I don't see this code in your [github repo](https://github.com/pohjie/pohjie.github.io), 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`. – Brad West Feb 09 '21 at 13:23
  • @BradWest Thanks for replying! It turns out I did not do `gem install bundler`, which is why I had issues with jekyll! – pohjie Feb 11 '21 at 09:14
  • are u using a newer version of ruby? x=> 3? – Adi Prasetyo Jun 06 '21 at 22:54

4 Answers4

4

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.

Lars Kiesow
  • 140
  • 5
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
    
bmaupin
  • 14,427
  • 5
  • 89
  • 94
  • 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. – mold Jul 30 '23 at 06:26
2

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.

Ragav Y
  • 1,662
  • 1
  • 18
  • 32
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

Liviu Stefan
  • 183
  • 8