Ruby - Troubleshooting26 Dec 2017
- Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
- uninitialized constant Gem::BundlerVersionFinder (NameError)
- can’t find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
- [__NSCFConstantString initialize] may have been in progress in another thread when fork() was called
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.
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)
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
bundle for those projects as well in that case).
it has turned out the problem was caused by specific version of either
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)
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
$ 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  pry(main)> Profile.count objc: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. objc: +[__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.
error has something to do with the latest version of
psql (12.1) that must be
pg gem (
psql is provided by
libpq package in my case).
libpqformula to install old version (11.7)
$ brew edit libpq
# /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/libpq.rb class Libpq < Formula desc "Postgres C API library" homepage "https://www.postgresql.org/docs/12/libpq.html" - url "https://ftp.postgresql.org/pub/source/v12.1/postgresql-12.1.tar.bz2" - sha256 "a09bf3abbaf6763980d0f8acbb943b7629a8b20073de18d867aecdb7988483ed" + url "https://ftp.postgresql.org/pub/source/v11.7/postgresql-11.7.tar.bz2" + sha256 "324ae93a8846fbb6a25d562d271bc441ffa8794654c5b2839384834de220a313" revision 1
libpqpackage from source
$ brew reinstall libpq --build-from-source $ psql --version psql (PostgreSQL) 11.7
if you try to install
brewwill fallback to building from source because old versions of
libpqbottle are not available.
pggem to build native extensions against old version of
$ bundle remove pg
NOTE: it doesn’t work if you remove
gem 'pg'from Gemfile manually and run
# Gemfile + gem 'pg'
rollback changes in
$ cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core $ git checkout Formula/libpq.rb $ cd -
$ brew reinstall libpq $ psql --version psql (PostgreSQL) 12.1