We don’t need ‘therubyracer’ and the libv8 error for compiling native extensions
This article is about the error:
Installing libv8 3.16.14.19 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
and the fact that we don’t need and probably you don’t need therubyracer.
There are two solutions for the above error:
# To install libv8 with a V8 without precompiling V8
$ gem install libv8 -v '3.16.14.19' -- --with-system-v8
# Or to comment therubyracer in your Gemfile and not to use it.
# gem 'therubyracer'
We went for the later. Here are more details
What is libv8 and therubyracer
From libv8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome and in Node.js, among others.
What therubyracer does is to embeds the V8 Javascript Interpreter into ruby.
In Rails there is the execjs gem used in assets precompilations.
ExecJS lets you run JavaScript code from Ruby. It automatically picks the best runtime available to evaluate your JavaScript program, then returns the result to you as a Ruby object.
https://github.com/sstephenson/execjs
This means that execjs needs a JS runtime and it uses the one provided by therubyracer, libv8 and V8. But it can use other runtimes as well, like Node.
What is the libv8 compilation error?
The libv8 error is because it can not compile V8 on the machine. V8 is developed in C++. To successfully compile it the machine must have all the dependencies needed for compilation. You can try to compile it from scratch or you could use an already compiled one. Compiling from scratch takes time to resolve all the dependencies.
But we didn’t need therubyracer
Turns out that in this specific platform we don’t need therubyracer, because we already have Node because of webpacker/webpack and we have it on all the machines and we have it on production on Heroku.
therubyracer is also discouraged on Heroku –
If you were previously using
therubyracer
ortherubyracer-heroku
, these gems are no longer required and strongly discouraged as these gems use a very large amount of memory.A version of Node is installed by the Ruby buildpack that will be used to compile your assets.
https://devcenter.heroku.com/articles/rails-asset-pipeline#therubyracer
therubyracer is great for starting quickly especially when there is no node. But considering there there was node on all of our machines we just don’t need therubyracer.
As a result the slug size on heroku was reduced from 210M to 195.9M. No bad. I guess the memory consumption will also be reduced.
remote: -----> Compressing...
remote: Done: 210M
remote: -----> Launching...
remote: Released v5616
remote: -----> Compressing...
remote: Done: 195.9M
remote: -----> Launching...
remote: Released v5617
How did we came about this error?
Every Wednesday we do an automatic bundle update to see what’s new and update all the gems (of course if the tests pass). This Wednesday the build failed, because of the libv8 error and native compilation.
It was just an unused dependency left in the Gemfile.
Reply
You must be logged in to post a comment.