Ruby - Troubleshooting


Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

the error occurred after installing a new Ruby version (2.5.0):

$ bundle
...
An error occurred while installing json (1.8.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.3'` succeeds before bundling.

solution

try to update offending gem:

$ bundle update json

uninitialized constant Gem::BundlerVersionFinder (NameError)

$ berks
...
/Users/tap/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/dependency.rb:283:in `matching_specs': uninitialized constant Gem::BundlerVersionFinder (NameError)

solution

error was gone after upgrading Ruby version from 2.5.0 to 2.5.1:

$ echo 2.5.1 > .ruby-version

if this doesn’t help, try to clean up old versions of installed gems (this will remove currently installed versions as well):

$ gem cleanup
$ bundle

gem cleanup removes bundled gems only (gems specified in Gemfile of current project) though it might affect other projects if they are using the same gems (run bundle for those projects as well in that case).

UPDATE

it has turned out the problem was caused by specific version of either berkshelf or chef or both.

old versions (error is present):

gem 'berkshelf', '6.3.1'
gem 'chef', '13.5.3'

old versions (error is gone):

gem 'berkshelf', '7.0.2'
gem 'chef', '14.1.1'

can’t find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)

$ bundle
Traceback (most recent call last):
	2: from /Users/tap/.rbenv/versions/2.5.0/bin/bundle:23:in `<main>'
	1: from /Users/tap/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/Users/tap/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)

solution

  1. https://stackoverflow.com/a/54038218/3632318

find current Bundler version:

$ gem list --local bundler

*** LOCAL GEMS ***

bundler (2.0.2)

find Bundler version in Gemfile.lock:

# Gemfile.lock

BUNDLED WITH
  1.16.1

now there are 2 possible solutions:

sync Gemfile.lock to Bundler version

  # Gemfile.lock

  BUNDLED WITH
-   1.16.1
+   2.0.1

sync Bundler version to Gemfile.lock

  1. https://bundler.io/blog/2019/01/04/an-update-on-the-bundler-2-release.html
$ gem install bundler -v 1.16.1

in many cases this solution is preferable since it’s easier and causes less problems with CI and deployment.

[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called

$ rails console
[1] pry(main)> Profile.count
objc[29838]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[29838]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

solution

  1. https://github.com/puma/puma/issues/2084

error has something to do with the latest version of psql (12.1) that must be used by pg gem (psql is provided by libpq package in my case).