The newest version of Rails, 6.0.2, comes with a package.json that uses rails/webpack version 4.2.2 which requires Node 8.
The prevailing internet wisdom seems to be to use RAILS_SKIP_ASSET_COMPILATION=true and instead use an .ebextension/fix_rails_6.config file containing
commands:
02_download_nodejs:
command: "curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -"
03_install_nodejs:
command: "yum -y install nodejs"
container_commands:
19_precompile:
command: "bundle exec rake assets:precompile"
(full file https://gist.github.com/lettergram/7384acdc3a157579a1692cc0af09d33a)
However, this results in an error Webpacker requires Node.js >= 8.16.0 and you are using 6.17.1...
How can I get the precompile to use the Node 8 that was already installed?
I got this working just now with the following (found here):
# .ebextensions/fix_rails_6.config
commands:
00_remove_node_6_if_present:
command: "/bin/rm -rf /var/cache/yum && /usr/bin/yum remove -y nodejs && /bin/rm /etc/yum.repos.d/nodesource* && /usr/bin/yum clean all && rm -rf /var/cache/yum"
ignoreErrors: true
01_download_nodejs:
command: "curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash -"
02_install_nodejs:
command: "yum -y install nodejs"
03_install_yarn:
command: "sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo && sudo yum install yarn -y"
04_mkdir_webapp_dir:
command: "mkdir /home/webapp"
ignoreErrors: true
05_chown_webapp_dir:
command: "chown webapp:webapp /home/webapp"
ignoreErrors: true
06_chmod_webapp_dir:
command: "chmod 0744 /home/webapp"
ignoreErrors: true
07_chmod_logs:
command: "chown webapp:webapp -R /var/app/current/log/"
ignoreErrors: true
08_create_log_file:
command: "touch /var/app/current/log/production.log"
ignoreErrors: true
09_chown_log_production:
command: "chown webapp:webapp /var/app/current/log/production.log"
ignoreErrors: true
10_chmod_log_dir:
command: "chmod 0664 -R /var/app/current/log/"
ignoreErrors: true
11_update_bundler:
command: "gem update bundler"
ignoreErrors: true
12_chown_current:
command: "chown webapp:webapp -R /var/app/current/"
ignoreErrors: true
13_chmod_current:
command: "chmod 0755 -R /var/app/current/"
ignoreErrors: true
14_chown_current:
command: "chown webapp:webapp -R /var/app/ondeck/"
ignoreErrors: true
15_chown_current:
command: "chmod 0644 -R /var/app/ondeck/"
ignoreErrors: true
container_commands:
16_install_webpack:
command: "npm install --save-dev webpack"
17_precompile:
command: "bundle exec rake assets:precompile"
I had to make a change to ensure node 6 was removed and node 12 installed instead adding && rm -rf /var/cache/yum to the end of the 00_remove_node_6_if_present command as it was still installing node 6 with the original.
However I encountered more grief with the NGINX proxy after this, which I fixed by changing the webpacker public_output_path to assets instead as I decided to use webpacker for everything rather than sprockets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With