gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 07:15:02 26 4
gpt4 key购买 nike

我正在尝试为我的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com