Jekyll site deployment fails on build step because it cannot find Gem

I have a Jekyll-based website. I also have a Ruby script that I want to run as part of the build step. I have a Makefile with the following contents:

	bundle install
	npm install

build: install
	bundle exec jekyll build --strict-front-matter

serve: install
	bundle exec jekyll serve --strict-front-matter --watch

When deploying, I can see Netlify detects my Gemfile and installs the gems in the “Initializing” step. But the “Building” step fails with the following error:

12:30:10 AM: /opt/buildhome/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require": cannot load such file -- jekyll/utils (LoadError)
	from /opt/buildhome/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require"
	from bin/superstars.rb:4:in `<main>"

I have the jekyll gem declared in my Gemfile. I can also see it in my Gemfile.lock file, and also in the log output in Netlify. So why can my Ruby script not find the file when it is being invoked?

Any one?

Deployments are blocked right now. Why does Netlify not find a file from a dependency that’s installed from the previous step? How is one meant to use Ruby gems as part of their build process if they disappear after a bundle install? Where are gems installed?

@hrishikesh Any idea what might be happening here?

(Unfortunately I’m utterly useless as I haven’t worked with Ruby in maybe 8 years)

What site is this about?

@hrishikesh It’s a Jekyll-based site, but I want to run a custom Ruby script as part of the build process before deploying.

Sorry, to be specific, I means to ask which site are you having this issue on?


Yeah this is interesting. Everything appears to be setup right as far as I can check. Do you mind sharing your repo?

@hrishikesh Sure. Just made it public: GitHub - martinbean/

I have also noticed this in the output log of failed builds:

/opt/buildhome/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require": cannot load such file -- jekyll (LoadError)
	from /opt/buildhome/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require"
	from bin/superstars.rb:4:in `<main>"

The path looks a bit funky. It references ruby-2.7.2… and then …/ruby/2.7.0…?

I deployed your repo on a new site and can’t get that error. Did I have to do something specific?

I did get another error however, but that’s some CSS error which can probably be easily fixed: Deploy details | Deploys | f-112896 | Netlify

@hrishikesh Nope, don’t need to do anything specific. All I did was create the site in Netlify, set the source repository, and add the following as the build command:

bin/superstars.rb && jekyll build --strict-front-matter

But then it just fails with these Ruby errors about require not being able to find files, despite the corresponding gems being installed.

If you’ve managed to deploy it via another site then I think I’ll just delete and try setting up from scratch.

@hrishikesh …and back to the same behaviour.

If I leave the build command as bundle exec jekyll build then it builds the Jekyll site just fine (I fixed that CSS error). But as soon as I update the command to also run bin/superstars.rb before, the build fails.

Again, the build command I’ve defined is:

bin/superstars.rb && bundle exec jekyll build

The error I get:

/opt/buildhome/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require": cannot load such file -- jekyll (LoadError)
	from /opt/buildhome/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require"
	from bin/superstars.rb:4:in `<main>"

This is interesting. I tried using gem query --local command which should list the installed dependencies and it doesn’t list jekyll: Deploy details | Deploys | f-112896 | Netlify

Not sure why, but leaving this note till I can investigate further.

I was able to get this working after the following changes:

  • The Ruby version was changed to 3.1.2
  • Changed the build command to gem install jekyll bundler nokogiri && bin/superstars.rb && bundle exec jekyll build

By working, I mean that it finally failed on the SCSS error.