Activating bundler (~> 2.4) failed:

I’m attempting to include asciidoc and rst support on my hugo site and it works fine locally, but if I try to build with it in Netlify it seems like it cannot find the Bundler. I’m new to using this kind of dependency so it’s likely user error. However, it says that the bundler is used and the gems are installed during the initializing phase.

Initializing log

9:41:28 PM: Attempting Ruby version 2.7.2, read from environment
9:41:29 PM: Using Ruby version 2.7.2
9:41:29 PM: Using Bundler version 2.4.22 from Gemfile.lock
9:41:30 PM: Started restoring cached ruby gems
9:41:30 PM: Finished restoring cached ruby gems
9:41:30 PM: Installing gem bundle
9:41:30 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
9:41:30 PM: [DEPRECATED] The --binstubs option will be removed in favor of `bundle binstubs --all`
9:41:31 PM: Fetching gem metadata from https://rubygems.org/........
9:41:31 PM: Resolving dependencies...
9:41:31 PM: Fetching asciidoctor 2.0.22
9:41:31 PM: Installing asciidoctor 2.0.22
9:41:31 PM: Bundle complete! 1 Gemfile dependency, 2 gems now installed.
9:41:31 PM: Bundled gems are installed into `/opt/build/cache/bundle`
9:41:31 PM: Gem bundle installed

Build log

9:41:44 PM: Start building sites …
9:41:44 PM: hugo v0.120.0-20c3bae2c4839ec993ec3c353da4fd7b09215cd8+extended linux/amd64 BuildDate=2023-10-30T14:06:47Z VendorInfo=gohugoio
9:41:44 PM: ERROR reference/layouts/shortcodes/ascii.md: Activating bundler (~> 2.4) failed:
9:41:44 PM: ERROR reference/layouts/shortcodes/ascii.md: Could not find 'bundler' (2.4.22) required by your /opt/build/repo/Gemfile.lock.
9:41:44 PM: ERROR reference/layouts/shortcodes/ascii.md: To update to the latest version installed on your system, run `bundle update --bundler`.
9:41:44 PM: ERROR reference/layouts/shortcodes/ascii.md: To install the missing version, run `gem install bundler:2.4.22`
9:41:44 PM: ERROR reference/layouts/shortcodes/ascii.md: Checked in 'GEM_PATH=/opt/buildhome/.gem/ruby/2.7.0:/opt/buildhome/.rvm/rubies/ruby-2.7.2/lib/ruby/gems/2.7.0', execute `gem env` for more information
9:41:44 PM: ERROR reference/layouts/shortcodes/ascii.md: To install the version of bundler this project requires, run `gem install bundler -v '~> 2.4'`
9:41:44 PM: ERROR asciidoctor rendering reference/layouts/shortcodes/ascii.md: failed to execute binary "asciidoctor" with args [--no-header-footer -]: Activating bundler (~> 2.4) failed:
9:41:44 PM: Could not find 'bundler' (2.4.22) required by your /opt/build/repo/Gemfile.lock.
9:41:44 PM: To update to the latest version installed on your system, run `bundle update --bundler`.
9:41:44 PM: To install the missing version, run `gem install bundler:2.4.22`
9:41:44 PM: Checked in 'GEM_PATH=/opt/buildhome/.gem/ruby/2.7.0:/opt/buildhome/.rvm/rubies/ruby-2.7.2/lib/ruby/gems/2.7.0', execute `gem env` for more information

For anyone in the future who is curious about how to resolve this issue, you need to update the security.exec.osEnv section of your hugo config with the following:

  osEnv: 
    - (?i)^(PATH|PATHEXT|APPDATA|TMP|TEMP|TERM|HOME|GEM_PATH)$

This whitelists the GEM_PATH so Hugo can access it.

I’ve documented the steps here: Enable AsciiDoc | MiloDocs

Hi thanks for sharing your solution with the community. This is helpful! (;