rubyjs / therubyracer

Embed the V8 Javascript Interpreter into Ruby
1.67k stars 190 forks source link

Installing on Ruby > 3.0 #467

Closed AryeShemesh closed 7 months ago

AryeShemesh commented 1 year ago

Hi,

I'm trying to upgrade a Ruby on Rails app from 2.x to 3.x.

While running bundle install I got the following error:

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

    current directory: /home/arye/.rvm/gems/ruby-3.1.2/gems/therubyracer-0.12.3/ext/v8
/home/arye/.rvm/rubies/ruby-3.1.2/bin/ruby -I /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0 -r ./siteconf20220801-12917-dtz58x.rb extconf.rb
checking for -lpthread... yes
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/home/arye/.rvm/rubies/ruby-3.1.2/bin/$(RUBY_BASE_NAME)
    --with-pthread-dir
    --without-pthread-dir
    --with-pthread-include
    --without-pthread-include=${pthread-dir}/include
    --with-pthread-lib
    --without-pthread-lib=${pthread-dir}/lib
    --with-pthreadlib
    --without-pthreadlib
    --enable-debug
    --disable-debug
/home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/psych/class_loader.rb:99:in `find': Tried to load unspecified class: Libv8::Location::Vendor (Psych::DisallowedClass)
    from /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/psych/class_loader.rb:28:in `load'
    from /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:424:in `resolve_class'
    from /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:213:in `visit_Psych_Nodes_Mapping'
    from /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'
    from /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'
    from /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'
    from /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:318:in `visit_Psych_Nodes_Document'
    from /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/psych/visitors/visitor.rb:30:in `visit'
    from /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/psych/visitors/visitor.rb:6:in `accept'
    from /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/psych/visitors/to_ruby.rb:35:in `accept'
    from /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/psych.rb:335:in `safe_load'
    from /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/psych.rb:370:in `load'
    from /home/arye/.rvm/gems/ruby-3.1.2/gems/libv8-3.16.14.19-x86_64-linux/ext/libv8/location.rb:16:in `block in load!'
    from /home/arye/.rvm/gems/ruby-3.1.2/gems/libv8-3.16.14.19-x86_64-linux/ext/libv8/location.rb:15:in `open'
    from /home/arye/.rvm/gems/ruby-3.1.2/gems/libv8-3.16.14.19-x86_64-linux/ext/libv8/location.rb:15:in `load!'
    from /home/arye/.rvm/gems/ruby-3.1.2/gems/libv8-3.16.14.19-x86_64-linux/lib/libv8.rb:6:in `configure_makefile'
    from extconf.rb:32:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/arye/.rvm/gems/ruby-3.1.2/extensions/x86_64-linux/3.1.0/therubyracer-0.12.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/arye/.rvm/gems/ruby-3.1.2/gems/therubyracer-0.12.3 for inspection.
Results logged to /home/arye/.rvm/gems/ruby-3.1.2/extensions/x86_64-linux/3.1.0/therubyracer-0.12.3/gem_make.out

  /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:95:in `run'
  /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:47:in `block in build'
  /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/tempfile.rb:317:in `open'
  /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:26:in `build'
  /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:161:in `build_extension'
  /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:195:in `block in build_extensions'
  /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:192:in `each'
  /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:192:in `build_extensions'
  /home/arye/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/installer.rb:853:in `build_extensions'
  /home/arye/.rvm/gems/ruby-3.1.2/gems/bundler-2.3.19/lib/bundler/rubygems_gem_installer.rb:72:in `build_extensions'
  /home/arye/.rvm/gems/ruby-3.1.2/gems/bundler-2.3.19/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /home/arye/.rvm/gems/ruby-3.1.2/gems/bundler-2.3.19/lib/bundler/source/rubygems.rb:207:in `install'
  /home/arye/.rvm/gems/ruby-3.1.2/gems/bundler-2.3.19/lib/bundler/installer/gem_installer.rb:54:in `install'
  /home/arye/.rvm/gems/ruby-3.1.2/gems/bundler-2.3.19/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /home/arye/.rvm/gems/ruby-3.1.2/gems/bundler-2.3.19/lib/bundler/installer/parallel_installer.rb:186:in `do_install'
  /home/arye/.rvm/gems/ruby-3.1.2/gems/bundler-2.3.19/lib/bundler/installer/parallel_installer.rb:177:in `block in worker_pool'
  /home/arye/.rvm/gems/ruby-3.1.2/gems/bundler-2.3.19/lib/bundler/worker.rb:62:in `apply_func'
  /home/arye/.rvm/gems/ruby-3.1.2/gems/bundler-2.3.19/lib/bundler/worker.rb:57:in `block in process_queue'
  /home/arye/.rvm/gems/ruby-3.1.2/gems/bundler-2.3.19/lib/bundler/worker.rb:54:in `loop'
  /home/arye/.rvm/gems/ruby-3.1.2/gems/bundler-2.3.19/lib/bundler/worker.rb:54:in `process_queue'
  /home/arye/.rvm/gems/ruby-3.1.2/gems/bundler-2.3.19/lib/bundler/worker.rb:91:in `block (2 levels) in create_threads'

An error occurred while installing therubyracer (0.12.3), and Bundler cannot continue.

In Gemfile:
  therubyracer

As far as I understand, this is the same as this mini racer issue:

Ruby 3 uses Psych 4.x to parse Yaml files, and the libv8 version required by therubyracer (~> 3.16.14.15) did not fix this issue yet. So for the rubyracer to support Ruby 3.x it seems to need to update it's libv8 dependecy version.

If so, is there a plan to do so and support Ruby 3.x?

VelizarHristov commented 1 year ago

It works on Ruby 3.0.x, however it doesn't work on Ruby 3.1.x. I'm using it with Ruby 3.0.4

HLFH commented 1 year ago

@VelizarHristov Ok thanks. Currently using ruby 3.0.5 and it seems to work well. I will wait to upgrade to ruby 3.2.0.

VelizarHristov commented 1 year ago

I don't expect it to work on Ruby 3.2 or later. It seems like this is not a bug that they're going to fix, but rather they removed something and now therubyracer needs to be updated to be compatible, however therubyracer is no longer maintaned so I don't think it will ever be compatible.

I found that my app worked just fine without therubyracer. It's possible that you might need to install Node.js on the computer, though.

ylecuyer commented 1 year ago

I had the same issue, I uninstalled psych >= 5 and I was able to install therubyracer

gem uninstall psych 5.0.1
gem install therubyracer
neil1023 commented 1 year ago

This worked fine for me on ruby 3.0.5. But as soon as I upgraded ruby to 3.2.1 and ran bundle install, I ran into that same stacktrace as OP. therubyracer is unmaintained and it's recommended to use mini_racer now. So I removed therubyracer from my gemfile and added mini_racer since the issue was resolved in mini_racer. Well technically, the issue was resolved in libv8-node version 6.10.0.0 I believe according to this message. I'm not sure which version of mini_racer started making use of libv8-node version 6.10.0.0 but I'm using version 0.6.3 for mini_racer and no longer facing the issue! 🎉

lloeki commented 7 months ago

Exceptionally, fixed here.

That said the project is unmaintained and this will be the last one.