ruby-on-rails - Gitlab CI 设置错误 - 找不到 JavaScript 运行时

标签 ruby-on-rails ruby node.js gitlab gitlab-ci

我正在尝试为我的 Ruby on Rails 项目设置 Gitlab CI,但遇到了一个我不知道如何修复的错误。

该应用程序在 Ruby 2.3.1、Rails 5.0 上运行,并使用 postgreSQL 数据库。

我当前的 .gitlab.ci.yml 文件如下所示:

# 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

所以它应该使用 NodeJS 作为运行时。但是,我收到以下错误:

$ 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)>'

最佳答案

您需要有一个 javascript 运行时(例如 nodejs)。您可以使用以下命令安装它:

对于 Ubuntu 用户

sudo apt-get install nodejs

对于 CentOS/RedHat 用户

sudo yum install nodejs

如果您无法安装 nodejs,您可以安装并使用 therubyracer gem。

来自存储库的描述:

Embed the V8 JavaScript interpreter into Ruby.

将这一行添加到您的 Gemfile

gem 'therubyracer', platforms: :ruby

关于ruby-on-rails - Gitlab CI 设置错误 - 找不到 JavaScript 运行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38453963/

相关文章:

ruby-on-rails - rails : How to limit number of items in has_many association (from Parent)

ruby-on-rails - 如何在 Amazon S3 中自定义 Rails 5.2 ActiveStorage 附件的路径?

ruby-on-rails - Rails 版本停留在 2.3.5 如何更新到 3.x

ruby-on-rails - 启动 Sidekiq 队列时的循环依赖

node.js - 从 node.js session 获取信息与从数据库获取信息

javascript - mongodb聚合过滤器并在nodejs上计数

ruby-on-rails - 无法按日期找到记录 [Rails 4]

ruby-on-rails - 转义 ruby​​ 字符串中的特殊字符以匹配 Salesforce SOQL 要求

ruby-on-rails - Rails、简单形式的 flatpickr 不起作用

javascript - 找不到模块的声明文件