Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 .gitlab.ci.yml file looks like this:

# https://hub.docker.com/r/library/ruby/tags/
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: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-service
services:
  - 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
before_script:
  - gem install bundler         # Bundler is not installed with the image
  - bundle install -j $(nproc)  # Install dependencies

rubocop:
  script:
  - rubocop

rspec:
  script:
  - rspec spec

rails:
  script:
  - 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 https://github.com/rails/execjs 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)>'
like image 967
Severin Avatar asked Jul 19 '16 09:07

Severin


People also ask

How do I verify a GitLab job configuration?

Paste in full .gitlab-ci.yml files or individual jobs configuration, to verify the basic syntax. When a .gitlab-ci.yml file is present in a project, you can also use the CI Lint tool to simulate the creation of a full pipeline . It does deeper verification of the configuration syntax.

How to troubleshoot GitLab CI CD?

Troubleshooting CI/CD 1 Verify syntax. An early source of problems can be incorrect syntax. ... 2 Verify variables. A key part of troubleshooting CI/CD is to verify which variables are present in a pipeline, and what their values are. 3 GitLab CI/CD documentation. ... 4 Common CI/CD issues. ... 5 Pipeline warnings. ...

Why didn’t my job run in GitLab?

GitLab determines if a job is added to a pipeline based on the only/except or rules defined for the job. If it didn’t run, it’s probably not evaluating as you expect. Before a pipeline can run, GitLab evaluates all the jobs in the configuration and tries to add them to all available pipeline types.

Why did my GitLab pipeline not run?

If it didn’t run, it’s probably not evaluating as you expect. Before a pipeline can run, GitLab evaluates all the jobs in the configuration and tries to add them to all available pipeline types. A pipeline does not run if no jobs are added to it at the end of the evaluation.


2 Answers

You need to have a javascript runtime (e.g. nodejs). You can install it by using the following command:

For Ubuntu Users

sudo apt-get install nodejs

For CentOS / RedHat Users

sudo yum install nodejs

In case you can't install nodejs you can install and then use therubyracer gem.

Description from repository:

Embed the V8 JavaScript interpreter into Ruby.

Add this line to your Gemfile

gem 'therubyracer', platforms: :ruby
like image 137
Farkhat Mikhalko Avatar answered Oct 10 '22 04:10

Farkhat Mikhalko


Gitlab-CI can be configured with the file .gitlab-ci.yml in this case:

before_script:
- apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs

can be used to install nodejs on the setup stage (source).

A complete before_script with jekyll can look like the following code (for instance, this is required for jekyll-minifier):

image: ruby:latest

variables:
  JEKYLL_ENV: production
  LC_ALL: C.UTF-8

before_script:
  - apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
  - ruby -v
  - which ruby
  - gem install bundler
  - bundle install

test:
  stage: test
  script:
  - bundle exec jekyll build -d test
  artifacts:
    paths:
    - test
  except:
  - master

pages:
  stage: deploy
  script:
  - bundle exec jekyll build -d public
  artifacts:
    paths:
    - public
  only:
  - master

like image 36
intika Avatar answered Oct 10 '22 04:10

intika