Unable to load ruby gem in build command

Hi,

I am attempting to run a script that fetches some data and generates a data file while building.

I have replaced the build command with my script bin/gen.

My script is a ruby script that requires several rubygems that should be installed already (goodreads and active_support).

This is when I get the error

2:59:14 AM: Executing user command: bin/gen
2:59:14 AM: /opt/buildhome/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- goodreads (LoadError)
2:59:14 AM: 	from /opt/buildhome/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
2:59:14 AM: 	from bin/generate-bookshelf:3:in `<main>'

Any ideas?

deploy: https://app.netlify.com/sites/gallant-mcclintock-c1ed09/deploys/5dd3a0a225053d00090a9287

I have run a test to see which gems are installed on the build server (by running gem list) and it appears that goodreads is not installed.

This is strange, because during the first build that had goodreads in the lockfile, I definitely saw it get installed in the log.

And for that matter, I don’t see any of the gems that are installed via bundler (jekyll, etc).

10:09:50 AM: Executing user command: bin/gen
10:09:50 AM: bigdecimal (default: 1.4.1)
10:09:50 AM: bundler (default: 1.17.2)
10:09:50 AM: cmath (default: 1.0.0)
10:09:50 AM: csv (default: 3.0.9)
10:09:50 AM: date (default: 2.0.0)
10:09:50 AM: dbm (default: 1.0.0)
10:09:50 AM: e2mmap (default: 0.1.0)
10:09:50 AM: etc (default: 1.0.1)
10:09:50 AM: fcntl (default: 1.0.0)
10:09:50 AM: fiddle (default: 1.0.0)
10:09:50 AM: fileutils (default: 1.1.0)
10:09:50 AM: forwardable (default: 1.2.0)
10:09:50 AM: gdbm (default: 2.0.0)
10:09:50 AM: gem-wrappers (1.4.0)
10:09:50 AM: io-console (default: 0.4.7)
10:09:50 AM: ipaddr (default: 1.2.2)
10:09:50 AM: irb (default: 1.0.0)
10:09:50 AM: json (default: 2.1.0)
10:09:50 AM: logger (default: 1.3.0)
10:09:50 AM: matrix (default: 0.1.0)
10:09:50 AM: mutex_m (default: 0.1.0)
10:09:50 AM: openssl (default: 2.1.2)
10:09:50 AM: ostruct (default: 0.1.0)
10:09:50 AM: prime (default: 0.1.0)
10:09:50 AM: psych (default: 3.1.0)
10:09:50 AM: rdoc (default: 6.1.0)
10:09:50 AM: rexml (default: 3.1.9)
10:09:50 AM: rss (default: 0.2.7)
10:09:50 AM: scanf (default: 1.0.0)
10:09:50 AM: sdbm (default: 1.0.0)
10:09:50 AM: shell (default: 0.7)
10:09:50 AM: stringio (default: 0.0.2)
10:09:50 AM: strscan (default: 1.0.0)
10:09:50 AM: sync (default: 0.5.0)
10:09:50 AM: thwait (default: 0.1.0)
10:09:50 AM: tracer (default: 0.1.0)
10:09:50 AM: webrick (default: 1.4.2)
10:09:50 AM: zlib (default: 1.0.0)
10:09:50 AM: /opt/buildhome/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- goodreads (LoadError)
10:09:50 AM: 	from /opt/buildhome/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
10:09:50 AM: 	from bin/generate-bookshelf:4:in `<main>'

Running bundle list shows the gems are installed.

10:15:22 AM: ==> bundle list
10:15:22 AM: Gems included by the bundle:
10:15:22 AM: The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
10:15:22 AM:   * activesupport (6.0.1)
10:15:22 AM:   * addressable (2.7.0)
10:15:22 AM:   * bundler (1.17.2)
10:15:22 AM:   * colorator (1.1.0)
10:15:22 AM:   * concurrent-ruby (1.1.5)
10:15:22 AM:   * domain_name (0.5.20190701)
10:15:22 AM:   * em-websocket (0.5.1)
10:15:22 AM:   * eventmachine (1.2.7)
10:15:22 AM:   * ffi (1.11.2)
10:15:22 AM:   * forwardable-extended (2.6.0)
10:15:22 AM:   * goodreads (0.7.0)
10:15:22 AM:   * hashie (2.1.2)
10:15:22 AM:   * http-accept (1.7.0)
10:15:22 AM:   * http-cookie (1.0.3)
10:15:22 AM:   * http_parser.rb (0.6.0)
10:15:22 AM:   * i18n (1.7.0)
10:15:22 AM:   * jekyll (4.0.0)
10:15:22 AM:   * jekyll-feed (0.12.1)
10:15:22 AM:   * jekyll-postcss (0.2.2)
10:15:22 AM:   * jekyll-purgecss (0.2.0)
10:15:22 AM:   * jekyll-sass-converter (2.0.1)
10:15:22 AM:   * jekyll-seo-tag (2.6.1)
10:15:22 AM:   * jekyll-sitemap (1.3.1)
10:15:22 AM:   * jekyll-watch (2.2.1)
10:15:22 AM:   * kramdown (2.1.0)
10:15:22 AM:   * kramdown-parser-gfm (1.1.0)
10:15:22 AM:   * liquid (4.0.3)
10:15:22 AM:   * listen (3.2.0)
10:15:22 AM:   * mercenary (0.3.6)
10:15:22 AM:   * mime-types (3.3)
10:15:22 AM:   * mime-types-data (3.2019.1009)
10:15:22 AM:   * minitest (5.13.0)
10:15:22 AM:   * netrc (0.11.0)
10:15:22 AM:   * oauth (0.5.4)
10:15:22 AM:   * pathutil (0.16.2)
10:15:22 AM:   * public_suffix (4.0.1)
10:15:22 AM:   * rb-fsevent (0.10.3)
10:15:22 AM:   * rb-inotify (0.10.0)
10:15:22 AM:   * rest-client (2.1.0)
10:15:22 AM:   * rouge (3.13.0)
10:15:22 AM:   * safe_yaml (1.0.5)
10:15:22 AM:   * sassc (2.2.1)
10:15:22 AM:   * terminal-table (1.8.0)
10:15:22 AM:   * thread_safe (0.3.6)
10:15:22 AM:   * tzinfo (1.2.5)
10:15:22 AM:   * unf (0.1.4)
10:15:22 AM:   * unf_ext (0.0.7.6)
10:15:22 AM:   * unicode-display_width (1.6.0)
10:15:22 AM:   * zeitwerk (2.2.1)
10:15:22 AM: /opt/buildhome/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- goodreads (LoadError)
10:15:22 AM: 	from /opt/buildhome/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
10:15:22 AM: 	from bin/generate-bookshelf:4:in `<main>'

I’ve preprended the that that the build log claims that bundled gems are installed to to the $LOAD_PATH, but still no success.

10:25:16 AM: ==> $LOAD_PATH
10:25:16 AM: /opt/build/cache/bundle
10:25:16 AM: /opt/buildhome/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0
10:25:16 AM: /opt/buildhome/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0/x86_64-linux
10:25:16 AM: /opt/buildhome/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby
10:25:16 AM: /opt/buildhome/.rvm/rubies/ruby-2.6.3/lib/ruby/vendor_ruby/2.6.0
10:25:16 AM: /opt/buildhome/.rvm/rubies/ruby-2.6.3/lib/ruby/vendor_ruby/2.6.0/x86_64-linux
10:25:16 AM: /opt/buildhome/.rvm/rubies/ruby-2.6.3/lib/ruby/vendor_ruby
10:25:16 AM: /opt/buildhome/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0
10:25:16 AM: /opt/buildhome/.rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0/x86_64-linux

I was able to get this working fairly easily on Zeit Now.

I would rather now switch because Netlify is a much more mature platform, but I will have no choice if I’m not able to get this working in the next few days.

Any ideas? Thanks

:raised_hands:

I solved it.

I needed to run my ruby script via bundle exec.

thanks so much for sharing your solution - this will absolutely help other people!