rails: Component 'json' of Ruby on Rails not working with Ruby 2.4.0

Install Ruby 2.4.0 In projects with RoR 3.2.xx, 4.2.xxx bundle install is fail:

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

current directory: /home/ruby/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator

/home/ruby/.rbenv/versions/2.4.0/bin/ruby -r ./siteconf20161225-17221-ivjmjg.rb extconf.rb creating Makefile

current directory: /home/ruby/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator make “DESTDIR=” clean

current directory: /home/ruby/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator make “DESTDIR=” compiling generator.c generator.c: In function ‘generate_json’: generator.c:861:25: error: ‘rb_cFixnum’ undeclared (first use in this function) } else if (klass == rb_cFixnum) { ^ generator.c:861:25: note: each undeclared identifier is reported only once for each function it appears in generator.c:863:25: error: ‘rb_cBignum’ undeclared (first use in this function) } else if (klass == rb_cBignum) { ^ generator.c: At top level: cc1: warning: unrecognized command line option “-Wno-self-assign” cc1: warning: unrecognized command line option “-Wno-constant-logical-operand” cc1: warning: unrecognized command line option “-Wno-parentheses-equality” cc1: warning: unrecognized command line option “-Wno-tautological-compare” Makefile:241: ошибка выполнения рецепта для цели «generator.o» make: *** [generator.o] Ошибка 1

make failed, exit code 2

Gem files will remain installed in /home/ruby/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/json-1.8.3 for inspection. Results logged to /home/ruby/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/json-1.8.3/gem_make.out

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.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 30
  • Comments: 17 (4 by maintainers)

Commits related to this issue

Most upvoted comments

@Drenmi gem json -v 1.8.5 is perfectly support it! On both RoR - 3.2.xx and 4.2.xx Only with gem 'json', github: 'flori/json', branch: 'v1.8' For many projects - is problem edit each Gemfile

Can still easier to fix this dependence in RoR?

JSON 1.8.5 is not published to RubyGems.

It has just been published 👍

It’s also failing for RoR 5.0.1.

Same issue here with gem ‘github-pages’, trying to install json…

Solved my issue by downgrading to ruby 2.3 using this :

`brew install rbenv ruby-build

Add rbenv to bash so that it loads every time you open a terminal echo ‘if which rbenv > /dev/null; then eval “$(rbenv init -)”; fi’ >> ~/.bash_profile source ~/.bash_profile

Install Ruby rbenv install 2.3.3 rbenv global 2.3.3 ruby -v`

from : https://gorails.com/setup/osx/10.12-sierra

Thanks for the helpful comments. Editing Gemfile.lock and changing json’s version from 1.8.3 to 1.8.5 fixed the issue for me. After that I could run bundle install without getting this error.

I got another error of course, but no longer this one. 😆

Solved: I just commented out, in my Gemfile, the offending gem, sdoc (~> 0.4.0) which resolved to 0.4.0 and depended on json (~> 1.8)… and re-run bundle update all right…

With Rails 5.0.1 & ruby 2.4.0, when doing bundle update (or gem install json -v '1.8.3') : Gem::Ext::BuildError: ERROR: Failed to build gem native extension. [...] error: ‘rb_cFixnum’ undeclared (first use in this function) [...] error: ‘rb_cBignum’ undeclared (first use in this function)

The JSON gem only supports the Integer unification in Ruby 2.4 starting from 2.0.0, and the Rails dependency is set to ~> 1.8, so you won’t be able to run Rails 4.2 with Ruby 2.4 for now.

It looks like this commit fixes it so we only have to wait for the next release. https://github.com/rails/rails/commit/47c49242913abbcdb8f798f53324769892d18c97

How about RoR 4.2.x.x? Any plans for releasing a fix to support Ruby 2.4 ?