You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CircleCI+Rails7执行assets:precompile报错‘yarn:not found’

CircleCI运行Rails视图RSpec测试的资产预编译问题

之前使用CircleCI运行Rails项目的RSpec测试一切正常,直到添加视图相关测试后,测试失败并报错:

ActionView::Template::Error:
The asset "application.css" is not present in the asset pipeline.

判断是资产未预编译导致的问题,于是在项目的config.yml中做了两处修改:

  • 引入cimg/node:19.2.0镜像,用于提供yarn运行环境
  • 添加bundle exec rails assets:precompile命令执行资产预编译

但执行构建时出现新错误,提示yarn: not found,完整错误日志如下:

#!/bin/bash -eo pipefail
bundle exec rake assets:precompile
sh: 1: yarn: not found
rake aborted!
jsbundling-rails: Command build failed, ensure yarn is installed and `yarn build` runs without errors
/home/circleci/my_project/vendor/bundle/ruby/3.1.0/gems/jsbundling-rails-1.0.3/lib/tasks/jsbundling/build.rake:5:in `block (2 levels) in <main>'
/home/circleci/my_project/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/home/circleci/.rubygems/bin/bundle:25:in `load'
/home/circleci/.rubygems/bin/bundle:25:in `<main>'
Tasks: TOP => assets:precompile => javascript:build
(See full trace by running task with --trace)

Exited with code exit status 1
CircleCI received exit code 1

根据镜像官方信息,cimg/node:19.2.0应该默认包含yarn,但实际构建过程中却找不到该命令。config.yml里第22行配置了这个node镜像,第53-55行添加了资产预编译的命令。


内容的提问来源于stack exchange,提问作者John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 22:55:27