Jekyll - Build failed due to a user error: Build script returned non-zero exit code: 2

I am building a Jekyll site that build fine locally using bundle exec jekyll build. The build is failing on the deploy step. The logs aren’t providing me a lot of information to go on.

Repo: GitHub - tjperry07/personal-site: The repo for my portfolio and blog site

4:28:42 PM: build-image version: 3ffff9df3d5419545acc1b673a54de348174406d (focal)
4:28:42 PM: buildbot version: 4613af4169363e3b38cfadfa4665d34cd1d1427b
4:28:42 PM: Fetching cached dependencies
4:28:42 PM: Failed to fetch cache, continuing with build
4:28:42 PM: Starting to prepare the repo for build
4:28:42 PM: No cached dependencies found. Cloning fresh repo
4:28:42 PM: git clone --filter=blob:none https://github.com/tjperry07/personal-site
4:28:42 PM: Preparing Git Reference pull/10/head
4:28:45 PM: Starting to install dependencies
4:28:45 PM: Python version set to 3.8
4:28:45 PM: Required ruby-3.2.2 is not installed.
4:28:45 PM: To install do: "rvm install "ruby-3.2.2""
4:28:45 PM: Attempting Ruby version 3.2.2, read from .ruby-version file
4:28:45 PM: Required ruby-3.2.2 is not installed - installing.
4:28:45 PM: Searching for binary rubies, this might take some time.
4:28:46 PM: Found remote file https://rubies.travis-ci.org/ubuntu/20.04/x86_64/ruby-3.2.2.tar.bz2
4:28:46 PM: Checking requirements for ubuntu.
4:28:46 PM: Requirements installation successful.
4:28:46 PM: ruby-3.2.2 - #configure
4:28:46 PM: ruby-3.2.2 - #download
4:28:47 PM: No checksum for downloaded archive, recording checksum in user configuration.
4:28:47 PM: ruby-3.2.2 - #validate archive
4:28:52 PM: ruby-3.2.2 - #extract
4:28:54 PM: ruby-3.2.2 - #validate binary
4:28:55 PM: ruby-3.2.2 - #setup
4:28:55 PM: ruby-3.2.2 - #gemset created /opt/buildhome/.rvm/gems/ruby-3.2.2@global
4:28:55 PM: ruby-3.2.2 - #importing gemset /opt/buildhome/.rvm/gemsets/global.gems........................................
4:28:56 PM: ruby-3.2.2 - #generating global wrappers........
4:28:56 PM: ruby-3.2.2 - #gemset created /opt/buildhome/.rvm/gems/ruby-3.2.2
4:28:56 PM: ruby-3.2.2 - #importing gemsetfile /opt/buildhome/.rvm/gemsets/default.gems evaluated to empty gem list
4:28:56 PM: ruby-3.2.2 - #generating default wrappers........
4:28:56 PM: Using /opt/buildhome/.rvm/gems/ruby-3.2.2
4:28:57 PM: Using Ruby version 3.2.2
4:28:57 PM: Started restoring cached ruby gems
4:28:57 PM: Finished restoring cached ruby gems
4:28:57 PM: Installing gem bundle
4:28:57 PM: [DEPRECATED] The `--path` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use `bundle config set --local path "/opt/build/cache/bundle"`, and stop using this flag
4:28:57 PM: [DEPRECATED] The --binstubs option will be removed in favor of `bundle binstubs --all`
4:28:59 PM: Fetching gem metadata from https://rubygems.org/...........
4:28:59 PM: Resolving dependencies...
4:29:05 PM: Fetching rake 13.1.0
4:29:05 PM: Installing rake 13.1.0
4:29:05 PM: Fetching base64 0.2.0
4:29:05 PM: Fetching concurrent-ruby 1.2.2
4:29:05 PM: Using ruby2_keywords 0.0.5
4:29:05 PM: Fetching erubi 1.12.0
4:29:05 PM: Fetching racc 1.7.3
4:29:05 PM: Fetching execjs 2.9.1
4:29:05 PM: Fetching popper_js 1.16.1
4:29:05 PM: Fetching thor 1.3.0
4:29:05 PM: Using bundler 2.4.10
4:29:05 PM: Fetching coffee-script-source 1.12.2
4:29:05 PM: Fetching colorator 0.1
4:29:05 PM: Fetching RedCloth 4.2.9
4:29:05 PM: Fetching bigdecimal 3.1.5
4:29:05 PM: Fetching connection_pool 2.4.1
4:29:05 PM: Fetching mutex_m 0.2.0
4:29:05 PM: Fetching builder 3.2.4
4:29:05 PM: Fetching crass 1.0.6
4:29:05 PM: Fetching rack 3.0.8
4:29:05 PM: Fetching addressable 2.4.0
4:29:05 PM: Fetching blankslate 2.1.2.4
4:29:05 PM: Fetching stringio 3.1.0
4:29:05 PM: Fetching io-console 0.7.0
4:29:05 PM: Fetching webrick 1.8.1
4:29:05 PM: Fetching ffi 1.16.3
4:29:05 PM: Fetching tilt 2.3.0
4:29:05 PM: Fetching matrix 0.4.2
4:29:05 PM: Fetching fast-stemmer 1.0.2
4:29:05 PM: Fetching net-dns 0.9.0
4:29:05 PM: Fetching minitest 5.20.0
4:29:05 PM: Fetching zeitwerk 2.6.12
4:29:05 PM: Fetching faraday-net_http 3.0.2
4:29:05 PM: Fetching gemoji 2.1.0
4:29:05 PM: Fetching public_suffix 1.5.3
4:29:05 PM: Installing base64 0.2.0
4:29:05 PM: Fetching jekyll-paginate 1.1.0
4:29:05 PM: Installing erubi 1.12.0
4:29:05 PM: Installing colorator 0.1
4:29:05 PM: Installing mutex_m 0.2.0
4:29:05 PM: Installing blankslate 2.1.2.4
4:29:05 PM: Installing faraday-net_http 3.0.2
4:29:05 PM: Installing connection_pool 2.4.1
4:29:05 PM: Installing stringio 3.1.0 with native extensions
4:29:05 PM: Installing fast-stemmer 1.0.2 with native extensions
4:29:05 PM: Installing builder 3.2.4
4:29:05 PM: Installing zeitwerk 2.6.12
4:29:05 PM: Installing execjs 2.9.1
4:29:05 PM: Installing crass 1.0.6
4:29:05 PM: Installing io-console 0.7.0 with native extensions
4:29:05 PM: Installing matrix 0.4.2
4:29:05 PM: Installing popper_js 1.16.1
4:29:05 PM: Installing tilt 2.3.0
4:29:05 PM: Installing jekyll-paginate 1.1.0
4:29:05 PM: Installing racc 1.7.3 with native extensions
4:29:05 PM: Installing webrick 1.8.1
4:29:05 PM: Installing net-dns 0.9.0
4:29:05 PM: Installing thor 1.3.0
4:29:05 PM: Fetching rb-fsevent 0.11.2
4:29:05 PM: Installing public_suffix 1.5.3
4:29:05 PM: Installing coffee-script-source 1.12.2
4:29:05 PM: Fetching kramdown 1.5.0
4:29:05 PM: Installing bigdecimal 3.1.5 with native extensions
4:29:05 PM: Installing addressable 2.4.0
4:29:05 PM: Installing minitest 5.20.0
4:29:05 PM: Installing rack 3.0.8
4:29:05 PM: Fetching liquid 2.6.2
4:29:05 PM: Fetching mercenary 0.3.6
4:29:05 PM: Fetching posix-spawn 0.3.15
4:29:05 PM: Fetching yajl-ruby 1.2.3
4:29:05 PM: Fetching redcarpet 3.3.2
4:29:05 PM: Fetching safe_yaml 1.0.5
4:29:05 PM: Fetching jekyll-feed 0.3.1
4:29:05 PM: Installing mercenary 0.3.6
4:29:05 PM: Installing safe_yaml 1.0.5
4:29:05 PM: Installing posix-spawn 0.3.15 with native extensions
4:29:05 PM: Fetching jekyll-sitemap 0.8.1
4:29:05 PM: Installing rb-fsevent 0.11.2
4:29:05 PM: Fetching maruku 0.7.0
4:29:05 PM: Installing liquid 2.6.2
4:29:05 PM: Fetching rdiscount 2.1.7
4:29:05 PM: Installing jekyll-feed 0.3.1
4:29:05 PM: Installing redcarpet 3.3.2 with native extensions
4:29:05 PM: Fetching unicode-display_width 1.8.0
4:29:05 PM: Installing jekyll-sitemap 0.8.1
4:29:05 PM: Installing unicode-display_width 1.8.0
4:29:05 PM: Installing rdiscount 2.1.7 with native extensions
4:29:05 PM: Fetching jekyll-figure 0.2.0
4:29:05 PM: Fetching rouge 4.2.0
4:29:05 PM: Installing jekyll-figure 0.2.0
4:29:05 PM: Installing kramdown 1.5.0
4:29:05 PM: Fetching drb 2.2.0
4:29:05 PM: Installing maruku 0.7.0
4:29:05 PM: Installing concurrent-ruby 1.2.2
4:29:05 PM: Fetching faraday 2.7.12
4:29:05 PM: Fetching parslet 1.5.0
4:29:05 PM: Fetching autoprefixer-rails 10.4.16.0
4:29:05 PM: Fetching coffee-script 2.4.1
4:29:05 PM: Fetching terminal-table 1.8.0
4:29:06 PM: Installing drb 2.2.0
4:29:06 PM: Installing coffee-script 2.4.1
4:29:06 PM: Installing parslet 1.5.0
4:29:06 PM: Installing terminal-table 1.8.0
4:29:06 PM: Installing faraday 2.7.12
4:29:06 PM: Fetching jekyll-coffeescript 1.0.1
4:29:06 PM: Installing jekyll-coffeescript 1.0.1
4:29:06 PM: Installing RedCloth 4.2.9 with native extensions
4:29:06 PM: Installing yajl-ruby 1.2.3 with native extensions
4:29:06 PM: Fetching rack-session 2.0.0
4:29:06 PM: Fetching rackup 2.1.0
4:29:06 PM: Fetching rack-test 2.1.0
4:29:06 PM: Installing rackup 2.1.0
4:29:06 PM: Installing rack-session 2.0.0
4:29:06 PM: Fetching classifier-reborn 2.3.0
4:29:06 PM: Installing rack-test 2.1.0
4:29:06 PM: Installing classifier-reborn 2.3.0
4:29:06 PM: Installing rouge 4.2.0
4:29:06 PM: Installing ffi 1.16.3 with native extensions
4:29:06 PM: Fetching sawyer 0.9.2
4:29:06 PM: Fetching toml 0.1.2
4:29:06 PM: Installing toml 0.1.2
4:29:06 PM: Fetching nokogiri 1.15.5 (x86_64-linux)
4:29:06 PM: Installing sawyer 0.9.2
4:29:06 PM: Installing autoprefixer-rails 10.4.16.0
4:29:06 PM: Fetching psych 5.1.1.1
4:29:06 PM: Fetching octokit 4.25.1
4:29:07 PM: Fetching sprockets 4.2.1
4:29:07 PM: Fetching i18n 1.14.1
4:29:07 PM: Fetching tzinfo 2.0.6
4:29:07 PM: Installing octokit 4.25.1
4:29:07 PM: Installing psych 5.1.1.1 with native extensions
4:29:07 PM: Installing i18n 1.14.1
4:29:07 PM: Installing tzinfo 2.0.6
4:29:07 PM: Installing sprockets 4.2.1
4:29:07 PM: Installing gemoji 2.1.0
4:29:07 PM: Fetching jekyll-gist 1.5.0
4:29:07 PM: Installing jekyll-gist 1.5.0
4:29:08 PM: Installing nokogiri 1.15.5 (x86_64-linux)
4:29:08 PM: Fetching loofah 2.22.0
4:29:08 PM: Installing loofah 2.22.0
4:29:08 PM: Fetching rails-html-sanitizer 1.6.0
4:29:08 PM: Installing rails-html-sanitizer 1.6.0
4:29:09 PM: Fetching reline 0.4.1
4:29:09 PM: Installing reline 0.4.1
4:29:10 PM: Fetching pygments.rb 0.6.3
4:29:10 PM: Fetching rdoc 6.6.1
4:29:10 PM: Installing pygments.rb 0.6.3
4:29:10 PM: Installing rdoc 6.6.1
4:29:10 PM: Fetching irb 1.10.1
4:29:10 PM: Installing irb 1.10.1
4:29:15 PM: Fetching activesupport 7.1.2
4:29:15 PM: Fetching sassc 2.4.0
4:29:15 PM: Fetching rb-inotify 0.10.1
4:29:15 PM: Fetching ethon 0.16.0
4:29:15 PM: Installing rb-inotify 0.10.1
4:29:15 PM: Installing ethon 0.16.0
4:29:15 PM: Fetching sass-listen 4.0.0
4:29:15 PM: Fetching listen 3.8.0
4:29:15 PM: Installing activesupport 7.1.2
4:29:15 PM: Installing sassc 2.4.0 with native extensions
4:29:15 PM: Installing sass-listen 4.0.0
4:29:15 PM: Installing listen 3.8.0
4:29:15 PM: Fetching sass 3.7.4
4:29:15 PM: Fetching typhoeus 0.8.0
4:29:15 PM: Fetching jekyll-watch 1.5.1
4:29:15 PM: Installing jekyll-watch 1.5.1
4:29:15 PM: Installing typhoeus 0.8.0
4:29:15 PM: Installing sass 3.7.4
4:29:15 PM: Fetching github-pages-health-check 0.6.1
4:29:15 PM: Installing github-pages-health-check 0.6.1
4:29:15 PM: Fetching jekyll-sass-converter 1.3.0
4:29:15 PM: Fetching rails-dom-testing 2.2.0
4:29:15 PM: Fetching html-pipeline 1.9.0
4:29:15 PM: Installing jekyll-sass-converter 1.3.0
4:29:15 PM: Fetching jekyll 2.4.0
4:29:15 PM: Installing html-pipeline 1.9.0
4:29:15 PM: Installing rails-dom-testing 2.2.0
4:29:15 PM: Installing jekyll 2.4.0
4:29:15 PM: Fetching actionview 7.1.2
4:29:15 PM: Fetching jekyll-redirect-from 0.8.0
4:29:15 PM: Fetching jemoji 0.5.0
4:29:15 PM: Fetching jekyll-mentions 0.2.1
4:29:15 PM: Fetching jekyll-seo-tag 1.2.0
4:29:15 PM: Fetching jekyll-archives 2.1.1
4:29:15 PM: Installing jekyll-redirect-from 0.8.0
4:29:15 PM: Installing jekyll-archives 2.1.1
4:29:15 PM: Installing jekyll-seo-tag 1.2.0
4:29:15 PM: Installing jekyll-mentions 0.2.1
4:29:15 PM: Installing jemoji 0.5.0
4:29:15 PM: Installing actionview 7.1.2
4:29:15 PM: Fetching github-pages 39
4:29:15 PM: Installing github-pages 39
4:29:15 PM: Fetching actionpack 7.1.2
4:29:15 PM: Installing actionpack 7.1.2
4:29:15 PM: Fetching railties 7.1.2
4:29:15 PM: Fetching sprockets-rails 3.4.2
4:29:15 PM: Installing sprockets-rails 3.4.2
4:29:15 PM: Installing railties 7.1.2
4:30:04 PM: Fetching sassc-rails 2.1.2
4:30:04 PM: Installing sassc-rails 2.1.2
4:30:04 PM: Fetching bootstrap 4.4.1
4:30:04 PM: Installing bootstrap 4.4.1
4:30:04 PM: Bundle complete! 12 Gemfile dependencies, 102 gems now installed.
4:30:04 PM: Bundled gems are installed into `/opt/build/cache/bundle`
4:30:04 PM: Post-install message from sass:
4:30:04 PM: Ruby Sass has reached end-of-life and should no longer be used.
4:30:04 PM: * If you use Sass as a command-line tool, we recommend using Dart Sass, the new
4:30:04 PM:   primary implementation: https://sass-lang.com/install
4:30:04 PM: * If you use Sass as a plug-in for a Ruby web framework, we recommend using the
4:30:04 PM:   sassc gem: https://github.com/sass/sassc-ruby#readme
4:30:04 PM: * For more details, please refer to the Sass blog:
4:30:04 PM:   https://sass-lang.com/blog/posts/7828841
4:30:04 PM: Post-install message from html-pipeline:
4:30:04 PM: -------------------------------------------------
4:30:04 PM: Thank you for installing html-pipeline!
4:30:04 PM: You must bundle Filter gem dependencies.
4:30:04 PM: See html-pipeline README.md for more details.
4:30:04 PM: https://github.com/jch/html-pipeline#dependencies
4:30:04 PM: -------------------------------------------------
4:30:04 PM: Gem bundle installed
4:30:04 PM: Started restoring cached go cache
4:30:04 PM: Finished restoring cached go cache
4:30:06 PM: go version go1.19.13 linux/amd64
4:30:06 PM: Using PHP version 8.0
4:30:07 PM: Downloading and installing node v18.19.0...
4:30:07 PM: Downloading https://nodejs.org/dist/v18.19.0/node-v18.19.0-linux-x64.tar.xz...
4:30:08 PM: Computing checksum with sha256sum
4:30:08 PM: Checksums matched!
4:30:10 PM: Now using node v18.19.0 (npm v10.2.3)
4:30:10 PM: Enabling Node.js Corepack
4:30:10 PM: Started restoring cached build plugins
4:30:10 PM: Finished restoring cached build plugins
4:30:10 PM: Successfully installed dependencies
4:30:10 PM: Starting build script
4:30:11 PM: Detected 1 framework(s)
4:30:11 PM: "jekyll" at version "unknown"
4:30:11 PM: Section completed: initializing
4:30:13 PM: ​
4:30:13 PM: Netlify Build                                                 
4:30:13 PM: ────────────────────────────────────────────────────────────────
4:30:13 PM: ​
4:30:13 PM: ❯ Version
4:30:13 PM:   @netlify/build 29.31.1
4:30:13 PM: ​
4:30:13 PM: ❯ Flags
4:30:13 PM:   baseRelDir: true
4:30:13 PM:   buildId: 657b73888dbdec000826627f
4:30:13 PM:   deployId: 657b73888dbdec0008266281
4:30:13 PM: ​
4:30:13 PM: ❯ Current directory
4:30:13 PM:   /opt/build/repo
4:30:13 PM: ​
4:30:13 PM: ❯ Config file
4:30:13 PM:   No config file was defined: using default values.
4:30:13 PM: ​
4:30:13 PM: ❯ Context
4:30:13 PM:   deploy-preview
4:30:13 PM: ​
4:30:13 PM: Build command from Netlify app                                
4:30:13 PM: ────────────────────────────────────────────────────────────────
4:30:13 PM: ​
4:30:13 PM: $ bundle exec jekyll build
4:30:13 PM: To use retry middleware with Faraday v2.0+, install `faraday-retry` gem
4:30:13 PM: jekyll 2.4.0 | Error:  undefined method `exists?" for File:Class
/opt/build/cache/bundle/ruby/3.2.0/gems/jekyll-2.4.0/lib/jekyll/configuration.rb:143:in `block in config_files": undefined method `exists?" for File:Class (NoMethodError)
4:30:13 PM:           File.exists? Jekyll.sanitized_path(source(override), "_config.#{ext}")
4:30:13 PM:               ^^^^^^^^
4:30:13 PM: Did you mean?  exist?
4:30:13 PM: 	from /opt/build/cache/bundle/ruby/3.2.0/gems/jekyll-2.4.0/lib/jekyll/configuration.rb:142:in `each"
	from /opt/build/cache/bundle/ruby/3.2.0/gems/jekyll-2.4.0/lib/jekyll/configuration.rb:142:in `find"
	from /opt/build/cache/bundle/ruby/3.2.0/gems/jekyll-2.4.0/lib/jekyll/configuration.rb:142:in `config_files"
	from /opt/build/cache/bundle/ruby/3.2.0/gems/jekyll-2.4.0/lib/jekyll.rb:90:in `configuration"
	from /opt/build/cache/bundle/ruby/3.2.0/gems/jekyll-2.4.0/lib/jekyll/command.rb:42:in `configuration_from_options"
	from /opt/build/cache/bundle/ruby/3.2.0/gems/jekyll-2.4.0/lib/jekyll/commands/build.rb:27:in `process"
	from /opt/build/cache/bundle/ruby/3.2.0/gems/jekyll-2.4.0/lib/jekyll/commands/build.rb:17:in `block (2 levels) in init_with_program"
	from /opt/build/cache/bundle/ruby/3.2.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute"
	from /opt/build/cache/bundle/ruby/3.2.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each"
	from /opt/build/cache/bundle/ruby/3.2.0/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute"
	from /opt/build/cache/bundle/ruby/3.2.0/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go"
	from /opt/build/cache/bundle/ruby/3.2.0/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program"
	from /opt/build/cache/bundle/ruby/3.2.0/gems/jekyll-2.4.0/bin/jekyll:18:in `<top (required)>"
	from /opt/build/cache/bundle/ruby/3.2.0/bin/jekyll:25:in `load"
	from /opt/build/cache/bundle/ruby/3.2.0/bin/jekyll:25:in `<main>"
	from /opt/buildhome/.rvm/rubies/ruby-3.2.2/bin/ruby_executable_hooks:22:in `eval"
	from /opt/buildhome/.rvm/rubies/ruby-3.2.2/bin/ruby_executable_hooks:22:in `<main>"
​
4:30:13 PM: "build.command" failed                                        
4:30:13 PM: ────────────────────────────────────────────────────────────────
4:30:13 PM: ​
4:30:13 PM:   Error message
4:30:13 PM:   Command failed with exit code 1: bundle exec jekyll build (https://ntl.fyi/exit-code-1)
4:30:13 PM: ​
4:30:13 PM:   Error location
4:30:13 PM:   In Build command from Netlify app:
4:30:13 PM:   bundle exec jekyll build
4:30:13 PM: ​
4:30:13 PM:   Resolved config
4:30:13 PM:   build:
4:30:13 PM:     command: bundle exec jekyll build
4:30:13 PM:     commandOrigin: ui
4:30:13 PM:     environment:
4:30:13 PM:       - REVIEW_ID
4:30:13 PM:     publish: /opt/build/repo/_site
4:30:13 PM:     publishOrigin: ui
4:30:14 PM: Failed during stage "building site": Build script returned non-zero exit code: 2
4:30:14 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
4:30:14 PM: Failing build: Failed to build site
4:30:14 PM: Finished processing build request in 1m32.574s

I figured it out. I’m not sure why the error is happening, but I know the cause. If someone from Netlify support can investigate further that would be great.

I came across this post on SO ruby - undefined method `exists?' for File:Class (NoMethodError)? - Stack Overflow which talks about exist? vs exists? in Ruby. I downgraded my ruby version from 3.2 to 3.0 and then I was able to get it to deploy.

Thanks for sharing your solution with the community! This will help other folks who stumble upon this thread in the future. :+1:t6: