【问题标题】:Deploying Rails 6.0 to AWS EB, Webpacker requires Node.js version error将 Rails 6.0 部署到 AWS EB,Webpacker 需要 Node.js 版本错误
【发布时间】:2020-08-04 20:10:33
【问题描述】:

我正在尝试将最近从 rails 5.2 更新到 6 的 rails 应用程序上传到 AWS Elastic Beanstalk。我们有其他人在做这件事,但由于大流行,他不得不离开——现在我们的网站有点陷入困境,我无法更新它。我已经搜索了我的问题的许多不同变体,但还没有解决方案。

该应用在 EB 上使用 rails 5.2 运行。我在本地运行 6.0 的应用程序。当我 eb deploy 我得到这个错误:

MacBook-Pro:app $ eb deploy
Starting environment deployment via CodeCommit
--- Waiting for Application Versions to be pre-processed ---
Finished processing application version app-0e294-200420_110159
2020-04-21 00:22:24    INFO    Environment update is starting.      
2020-04-21 00:23:07    INFO    Deploying new version to instance(s).
2020-04-21 00:27:59    ERROR   [Instance: i-0e613ac1fe175f3f6] Command failed on instance. Return code: 1 Output: (TRUNCATED)...-- : Writing /var/app/ondeck/public/assets/application-06fe3df6175ba0def3d0e732489f883d0c09de.css.gz
Webpacker requires Node.js ">=10.13.0" and you are using v6.17.1
Please upgrade Node.js https://nodejs.org/en/download/
Exiting!. 
Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/11_asset_compilation.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
2020-04-21 00:27:59    INFO    Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
2020-04-21 00:28:00    ERROR   Unsuccessful command execution on instance id(s) 'i-0e613ac1fe175f3f6'. Aborting the operation.
2020-04-21 00:28:00    ERROR   Failed to deploy application.        

ERROR: ServiceError - Failed to deploy application.

在此之前它给了我一个捆绑器错误,我可以通过将一个文件添加到安装正确版本的捆绑器的 .ebextensions 中来修复它。我想这个问题的解决方案是相似的。

这篇文章与我的问题很接近: Deploy rails react app with webpacker gem on AWS elastic beanstalk

所以我根据选择的答案将此文件添加到我的 .ebextensions 中:

01_update_note.config

commands:
  01_download_nodejs:
    command: curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
  02_install_nodejs:
    command: yum -y install nodejs

但是,它似乎没有做任何事情,我仍然得到同样的错误。我根据其他一些关于该问题的博客文章尝试了该文件的几个变体,但错误仍然存​​在。有没有人能够指出我正确的方向或对问题提供任何见解?抱歉,我对 AWS 或 EB 还不是很熟悉,但我会尽力回答其他问题。

【问题讨论】:

    标签: amazon-web-services ruby-on-rails-6 webpacker


    【解决方案1】:

    可能是后来yarn install造成的。 我尝试以下脚本并删除yarn install,然后设置RAILS_SKIP_ASSET_COMPILATION=false,它对我有用。

    commands:
      01_install_yarn:
        command: "sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo && curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash - && sudo yum install yarn -y"
      02_download_nodejs:
        command: curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash -
      03_install_nodejs:
        command: yum -y install nodejs
      04_install_packages:
        command: sudo yum install -y yarn
    

    【讨论】:

      【解决方案2】:

      这就是我在 Amazon Linux 2 上的做法:

      .platform/hooks/prebuild/yarn_config.sh中创建这个文件:

      #!/usr/bin/env bash
      
      curl --silent --location https://rpm.nodesource.com/setup_16.x | sudo bash -
      sudo yum -y install nodejs
      
      sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo
      sudo yum -y install yarn
      
      yarn install
      

      给它正确的权限:chmod +x .platform/hooks/prebuild/yarn_config.sh

      错误消失了,而您的资产仍在编译(与接受的答案不同)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-11-22
        • 1970-01-01
        • 2020-04-25
        • 2019-05-31
        • 1970-01-01
        • 2016-03-26
        • 2012-11-29
        • 2018-05-09
        相关资源
        最近更新 更多