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.
我正在尝试为我的Ruby on Rails项目设置Gitlab CI,但遇到了一个我不知道如何解决的错误。
The application is running on Ruby 2.3.1, Rails 5.0 and is using a postgreSQL database.
该应用程序在Ruby 2.3.1,Rails 5.0上运行,并使用postgreSQL数据库。
My current .gitlab.ci.yml file looks like this:
我当前的.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
So it's supposed to be using NodeJS as runtime. However, I get the following error:
所以它应该使用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)>'
1 个解决方案
#1
5
You need javascript runtime (nodejs), install them.
你需要javascript运行时(nodejs),安装它们。
Ubuntu Users
Ubuntu用户
sudo apt-get install nodejs
CentOS/RedHat Users
CentOS / RedHat用户
sudo yum install nodejs
If you can't install nodejs
you can use therubyracer
gem. Description from repository:
如果你不能安装nodejs你可以使用therubyracer gem。存储库中的描述:
Embed the V8 JavaScript interpreter into Ruby.
将V8 JavaScript解释器嵌入到Ruby中。
Add this lines to Gemfile
将此行添加到Gemfile
gem 'therubyracer', platforms: :ruby
#1
5
You need javascript runtime (nodejs), install them.
你需要javascript运行时(nodejs),安装它们。
Ubuntu Users
Ubuntu用户
sudo apt-get install nodejs
CentOS/RedHat Users
CentOS / RedHat用户
sudo yum install nodejs
If you can't install nodejs
you can use therubyracer
gem. Description from repository:
如果你不能安装nodejs你可以使用therubyracer gem。存储库中的描述:
Embed the V8 JavaScript interpreter into Ruby.
将V8 JavaScript解释器嵌入到Ruby中。
Add this lines to Gemfile
将此行添加到Gemfile
gem 'therubyracer', platforms: :ruby