将 rails 6 部署到 AWS Beanstalk 时,系统中未检测到 Yarn 可执行文件

Posted

技术标签:

【中文标题】将 rails 6 部署到 AWS Beanstalk 时,系统中未检测到 Yarn 可执行文件【英文标题】:Yarn executable was not detected in the system while deploying rails 6 to AWS Beanstalk 【发布时间】:2020-11-16 01:22:49 【问题描述】:

尝试在 AWS Beanstalk 上部署 Ruby on Rails 应用程序。 Ruby 版本是 2.6.6,Rails 版本是 5.2.3。 RDS 和其他设置已完成,但是当我不使用 eb deploy 时,它会在资产预编译时出错。错误是未检测到纱线。在这个应用程序中,我也有 webpack gem,因为需要这种纱线

+ su -s /bin/bash -c 'bundle exec /opt/elasticbeanstalk/support/scripts/check-for-rake-task.rb assets:precompile' webapp
  `/home/webapp` is not a directory.
  Bundler will use `/tmp/bundler20200726-3166-q5qdvj3166' as your home directory temporarily.
  + '[' false == true ']'
  + su -s /bin/bash -c 'bundle exec rake assets:precompile' webapp
  `/home/webapp` is not a directory.
  Bundler will use `/tmp/bundler20200726-3256-1yqrnzx3256' as your home directory temporarily.
  Yarn executable was not detected in the system.
  Download Yarn at https://yarnpkg.com/en/docs/install
  rake aborted!
  SassC::SyntaxError: Error: File to import not found or unreadable: bootstrap/scss/bootstrap.
          on line 16:1 of app/assets/stylesheets/application.scss
  >> @import "bootstrap/scss/bootstrap";
  
     ^
  /var/app/ondeck/app/assets/stylesheets/application.scss:16
  Tasks: TOP => assets:precompile
  (See full trace by running task with --trace) (Executor::NonZeroExitStatus)


[2020-07-26T15:41:34.604Z] ERROR [2838]  : Command CMD-AppDeploy failed!
[2020-07-26T15:41:34.604Z] INFO  [2838]  : Command processor returning results: 
"status":"FAILURE","api_version":"1.0","results":["status":"FAILURE","msg":"(TRUNCATED)...ootstrap.\n        on line 16:1 of app/assets/stylesheets/application.scss\n>> @import \"bootstrap/scss/bootstrap\";\n\n   ^\n/var/app/ondeck/app/assets/stylesheets/application.scss:16\nTasks: TOP => assets:precompile\n(See full trace by running task with --trace). \nHook /opt/elasticbeanstalk/hooks/appdeploy/pre/11_asset_compilation.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI","returncode":1,"events":[]],"truncated":"true"

虽然我在 .ebextensions 中创建了一个配置文件 yarn.config

 01_node_get:
cwd: /tmp
command: 'sudo curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -'

02_node_install:
cwd: /tmp
command: 'sudo yum -y install nodejs'

03_yarn_get:
cwd: /tmp
# don't run the command if yarn is already installed (file /usr/bin/yarn exists)
test: '[ ! -f /usr/bin/yarn ] && echo "yarn not installed"'
command: 'sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo'

04_yarn_install:
cwd: /tmp
test: '[ ! -f /usr/bin/yarn ] && echo "yarn not installed"'
command: 'sudo yum -y install yarn'

我该如何解决这个问题?

【问题讨论】:

【参考方案1】:

问题在于@import "bootstrap/scss/bootstrap" 的路径;

应该是

"node_modules/bootstrap/scss/bootstrap";

路径应该是相对于根的

【讨论】:

@import "bootstrap/scss/bootstrap"; @import "bootstrap/scss/bootstrap";基本上这些都在 node_modules 里面 好的,那么@import 应该是 ""node_modules/bootstrap/scss/bootstrap" 但在 Rails 中我们不推送 node_module ...它将使用 assets:precompile 构建

以上是关于将 rails 6 部署到 AWS Beanstalk 时,系统中未检测到 Yarn 可执行文件的主要内容,如果未能解决你的问题,请参考以下文章

AWS Elastic Beanstalk Ruby on Rails 6 应用程序部署错误与 nginx

无法将 Rails API 应用程序部署到 AWS Elastic Beanstalk

Rails 部署到 AWS ElasticBeanstalk/RDS 失败

如何为 ruby​​ 2.7.1 解决 AWS Elastic Beanstalk 上的 Rail 6 部署错误

为啥我的 Rails 应用程序无法部署到 AWS Elastic Beanstalk?

AWS Elastic Beanstalk Rails 4,已部署,需要帮助阅读日志文件和调试