Severin Severin - 1 year ago 386
Ruby Question

Gitlab CI setup error - Could not find a JavaScript runtime

I am trying to setup Gitlab CI for my Ruby on Rails project, but ran into an error that I don't know how to fix.

The application is running on Ruby 2.3.1, Rails 5.0 and is using a postgreSQL database.

My current file looks like this:

image: "ruby:2.3.0"

# Pick zero or more services to be used on all builds.
# Only needed when using a docker container to run your tests in.
# Check out:
- redis:latest
- postgres:latest
- node:latest

# This is a basic example for a gem or script which doesn't use
# services such as redis or postgres
- gem install bundler # Bundler is not installed with the image
- bundle install -j $(nproc) # Install dependencies

- rubocop

- rspec spec

- rails db:migrate
- rspec spec

So it's supposed to be using NodeJS as runtime. However, I get the following error:

$ rails db:migrate
rails aborted!
Bundler::GemRequireError: There was an error while trying to load the gem 'uglifier'.
Gem Load Error is: Could not find a JavaScript runtime. See for a list of available runtimes.
Backtrace for gem load error is:
/usr/local/bundle/gems/execjs-2.7.0/lib/execjs/runtimes.rb:58:in `autodetect'
/usr/local/bundle/gems/execjs-2.7.0/lib/execjs.rb:5:in `<module:ExecJS>'
/usr/local/bundle/gems/execjs-2.7.0/lib/execjs.rb:4:in `<top (required)>'
/usr/local/bundle/gems/activesupport-5.0.0.rc2/lib/active_support/dependencies.rb:293:in `require'
/usr/local/bundle/gems/activesupport-5.0.0.rc2/lib/active_support/dependencies.rb:293:in `block in require'
/usr/local/bundle/gems/activesupport-5.0.0.rc2/lib/active_support/dependencies.rb:259:in `load_dependency'
/usr/local/bundle/gems/activesupport-5.0.0.rc2/lib/active_support/dependencies.rb:293:in `require'
/usr/local/bundle/gems/uglifier-3.0.0/lib/uglifier.rb:5:in `<top (required)>'

Answer Source

You need javascript runtime (nodejs), install them.

Ubuntu Users

sudo apt-get install nodejs

CentOS/RedHat Users

sudo yum install nodejs

If you can't install nodejs you can use therubyracer gem. Description from repository:

Embed the V8 JavaScript interpreter into Ruby.

Add this lines to Gemfile

gem 'therubyracer', platforms: :ruby
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download