Search code examples
amazon-web-servicesruby-on-rails-6webpacker

Deploying Rails 6.0 to AWS EB, Webpacker requires Node.js version error


I am attempting to upload a rails app that was recently updated from rails 5.2 to 6 to AWS Elastic Beanstalk. We had someone else working on this, but with the pandemic he had to step away - and now our site is kind of in limbo and I have not been able to update it. I have searched many different variations of my problem but no solutions have worked yet.

The app was working on EB with rails 5.2. I have the app running in 6.0 locally. When I eb deploy I get this error:

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.

It was giving me a bundler error before this, that I was able to fix by adding a file into .ebextensions that installs the correct version of bundler. I figured the solution to this would be similar.

This post was close to my problem: Deploy rails react app with webpacker gem on AWS elastic beanstalk

So I added this file to my .ebextensions based off the selected answer of that:

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

However, it did not appear to do anything, I still get the same error. I tried a couple variations of the file based off a few other blog posts about the issue, but the error remains. Is anyone able to point me in the right direction or offer any insight into the problem? I apologize for not being very familiar with AWS or EB yet, but I will do my best to answer additional questions.


Solution

  • Maybe it is caused by yarn install later. I try the following scripts and remove yarn install then set RAILS_SKIP_ASSET_COMPILATION=false and it works for me.

    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