加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 02:56:33 所属栏目:百科 来源:网络整理
导读:我正在尝试为我的 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: "r
我正在尝试为我的 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读