Can't run rails app with a node version provided by docker.

Good day.

I’m trying to launch Rails app on fly.io, but can’t do so because of older version of node that docker keeps using. Here is a log:

flyctl launch                                                                            ✔  2.7.4  
An existing fly.toml file was found for app briefcake
App is not running, deploy...
Deploying briefcake
==> Validating app configuration
--> Validating app configuration done
Services
TCP 80/443 ⇢ 8080
Remote builder fly-builder-rough-hill-7331 ready
==> Building image with Buildpacks
--> docker host: 20.10.12 linux x86_64
20: Pulling from heroku/buildpacks
Digest: sha256:3d0ada09405874c6054025c6fa3e29ec77b9405463412971d72315a699ef5384
Status: Image is up to date for heroku/buildpacks:20
20: Pulling from heroku/pack
Digest: sha256:8a54ed2a34612ccd9c6395c998dc886e27272671841db39c0170fa05e7ea8083
Status: Image is up to date for heroku/pack:20
===> DETECTING
heroku/ruby     0.1.3
heroku/procfile 1.0.1
===> ANALYZING
Previous image with name "registry.fly.io/briefcake:cache" not found
===> RESTORING
===> BUILDING
-----> Installing bundler 2.2.21
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-3.1.2
-----> Loading Bundler Cache
-----> Installing dependencies using bundler 2.2.21
       Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=/layers/heroku_ruby/gems/vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
       Fetching gem metadata from https://rubygems.org/.........
       Fetching rake 13.0.6
       Installing rake 13.0.6
       Fetching concurrent-ruby 1.1.10
       Fetching builder 3.2.4
       Fetching erubi 1.10.0
       Fetching minitest 5.15.0
       Installing erubi 1.10.0
       Installing builder 3.2.4
       Using racc 1.6.0
       Fetching crass 1.0.6
       Installing minitest 5.15.0
       Installing concurrent-ruby 1.1.10
       Fetching rack 2.2.3
       Fetching nio4r 2.5.8
       Installing crass 1.0.6
       Installing nio4r 2.5.8 with native extensions
       Installing rack 2.2.3
       Fetching websocket-extensions 0.1.5
       Installing websocket-extensions 0.1.5
       Fetching marcel 1.0.2
       Installing marcel 1.0.2
       Fetching mini_mime 1.1.2
       Installing mini_mime 1.1.2
       Using digest 3.1.0
       Using timeout 0.2.0
       Using strscan 3.0.1
       Fetching public_suffix 4.0.7
       Fetching multi_json 1.15.0
       Installing public_suffix 4.0.7
       Installing multi_json 1.15.0
       Fetching statsd-ruby 1.5.0
       Installing statsd-ruby 1.5.0
       Fetching bcrypt 3.1.17
       Fetching msgpack 1.5.1
       Fetching browser 4.2.0
       Installing msgpack 1.5.1 with native extensions
       Installing browser 4.2.0
       Installing bcrypt 3.1.17 with native extensions
       Using bundler 2.3.7
       Fetching method_source 1.0.0
       Installing method_source 1.0.0
       Fetching thor 1.2.1
       Installing thor 1.2.1
       Fetching zeitwerk 2.5.4
       Installing zeitwerk 2.5.4
       Fetching orm_adapter 0.5.0
       Installing orm_adapter 0.5.0
       Fetching unf_ext 0.0.8.1
       Installing unf_ext 0.0.8.1 with native extensions
       Fetching execjs 2.8.1
       Installing execjs 2.8.1
       Fetching sax-machine 1.3.2
       Installing sax-machine 1.3.2
       Fetching ffi 1.15.5
       Installing ffi 1.15.5 with native extensions
       Fetching raabro 1.4.0
       Installing raabro 1.4.0
       Fetching webrick 1.7.0
       Installing webrick 1.7.0
       Fetching honeybadger 4.12.1
       Installing honeybadger 4.12.1
       Fetching http-form_data 2.3.0
       Installing http-form_data 2.3.0
       Fetching mime-types-data 3.2022.0105
       Installing mime-types-data 3.2022.0105
       Fetching multi_xml 0.6.0
       Installing multi_xml 0.6.0
       Fetching rb-fsevent 0.11.1
       Installing rb-fsevent 0.11.1
       Fetching mixpanel-ruby 2.2.2
       Installing mixpanel-ruby 2.2.2
       Fetching pg 1.3.5
       Installing pg 1.3.5 with native extensions
       Fetching php_serialize 1.2
       Installing php_serialize 1.2
       Fetching sanitize-url 0.1.4
       Installing sanitize-url 0.1.4
       Fetching turbolinks-source 5.2.0
       Installing turbolinks-source 5.2.0
       Fetching nokogiri 1.13.4 (x86_64-linux)
       Installing nokogiri 1.13.4 (x86_64-linux)
       Fetching websocket-driver 0.7.5
       Installing websocket-driver 0.7.5 with native extensions
       Fetching rack-test 1.1.0
       Installing rack-test 1.1.0
       Fetching warden 1.2.9
       Installing warden 1.2.9
       Fetching net-protocol 0.1.3
       Installing net-protocol 0.1.3
       Fetching mail 2.7.1
       Installing mail 2.7.1
       Fetching i18n 1.10.0
       Installing i18n 1.10.0
       Fetching tzinfo 2.0.4
       Installing tzinfo 2.0.4
       Fetching sprockets 4.0.3
       Installing sprockets 4.0.3
       Fetching addressable 2.8.0
       Installing addressable 2.8.0
       Fetching barnes 0.0.9
       Fetching uglifier 4.2.0
       Installing barnes 0.0.9
       Fetching unf 0.1.4
       Installing uglifier 4.2.0
       Installing unf 0.1.4
       Fetching mime-types 3.4.1
       Fetching puma 5.6.4
       Installing mime-types 3.4.1
       Installing puma 5.6.4 with native extensions
       Fetching turbolinks 5.2.1
       Installing turbolinks 5.2.1
       Fetching loofah 2.16.0
       Installing loofah 2.16.0
       Fetching net-imap 0.2.3
       Installing net-imap 0.2.3
       Fetching net-pop 0.1.1
       Installing net-pop 0.1.1
       Fetching net-smtp 0.3.1
       Installing net-smtp 0.3.1
       Fetching activesupport 7.0.2.3
       Installing activesupport 7.0.2.3
       Fetching et-orbi 1.2.7
       Installing et-orbi 1.2.7
       Fetching bootsnap 1.11.1
       Installing bootsnap 1.11.1 with native extensions
       Fetching domain_name 0.5.20190701
       Installing domain_name 0.5.20190701
       Fetching httparty 0.20.0
       Installing httparty 0.20.0
       Fetching rails-html-sanitizer 1.4.2
       Installing rails-html-sanitizer 1.4.2
       Fetching feedjira 3.2.1
       Installing feedjira 3.2.1
       Fetching rails-dom-testing 2.0.3
       Installing rails-dom-testing 2.0.3
       Fetching globalid 1.0.0
       Installing globalid 1.0.0
       Fetching activemodel 7.0.2.3
       Installing activemodel 7.0.2.3
       Fetching name_of_person 1.1.1
       Installing name_of_person 1.1.1
       Fetching fugit 1.5.3
       Installing fugit 1.5.3
       Fetching http-cookie 1.0.4
       Installing http-cookie 1.0.4
       Fetching actionview 7.0.2.3
       Installing actionview 7.0.2.3
       Fetching activejob 7.0.2.3
       Installing activejob 7.0.2.3
       Fetching activerecord 7.0.2.3
       Installing activerecord 7.0.2.3
       Fetching valid_email2 4.0.3
       Installing valid_email2 4.0.3
       Fetching validate_url 1.0.13
       Installing validate_url 1.0.13
       Fetching actionpack 7.0.2.3
       Installing actionpack 7.0.2.3
       Fetching activerecord-typedstore 1.4.0
       Installing activerecord-typedstore 1.4.0
       Fetching friendly_id 5.4.2
       Installing friendly_id 5.4.2
       Fetching actioncable 7.0.2.3
       Installing actioncable 7.0.2.3
       Fetching activestorage 7.0.2.3
       Installing activestorage 7.0.2.3
       Fetching actionmailer 7.0.2.3
       Installing actionmailer 7.0.2.3
       Fetching railties 7.0.2.3
       Installing railties 7.0.2.3
       Fetching sprockets-rails 3.4.2
       Installing sprockets-rails 3.4.2
       Fetching actionmailbox 7.0.2.3
       Installing actionmailbox 7.0.2.3
       Fetching actiontext 7.0.2.3
       Installing actiontext 7.0.2.3
       Fetching cssbundling-rails 1.1.0
       Installing cssbundling-rails 1.1.0
       Fetching responders 3.0.1
       Installing responders 3.0.1
       Fetching good_job 2.13.1
       Installing good_job 2.13.1
       Fetching jsbundling-rails 1.0.2
       Installing jsbundling-rails 1.0.2
       Fetching stimulus-rails 1.0.4
       Installing stimulus-rails 1.0.4
       Fetching rails 7.0.2.3
       Installing rails 7.0.2.3
       Fetching devise 4.8.1
       Installing devise 4.8.1
       Fetching devise_masquerade 1.3.11
       Installing devise_masquerade 1.3.11
       Fetching rb-inotify 0.10.1
       Fetching ffi-compiler 1.0.1
       Installing ffi-compiler 1.0.1
       Installing rb-inotify 0.10.1
       Fetching llhttp-ffi 0.4.0
       Installing llhttp-ffi 0.4.0 with native extensions
       Fetching listen 3.7.1
       Installing listen 3.7.1
       Fetching http 5.0.4
       Installing http 5.0.4
       Bundle complete! 41 Gemfile dependencies, 103 gems now installed.
       Gems in the groups 'development' and 'test' were not installed.
       Bundled gems are installed into `/layers/heroku_ruby/gems/vendor/bundle`
       Post-install message from httparty:
       When you HTTParty, you must party hard!
       Bundle completed (16.49s)
       Cleaning up the bundler cache.
       Removing bundler (2.2.21)
-----> Installing node-v12.16.2-linux-x64
-----> Installing yarn-v1.22.4
-----> Detecting rake tasks
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       yarn install v1.22.4
       [1/4] Resolving packages...
       [2/4] Fetching packages...
       info esbuild-android-64@0.14.38: The platform "linux" is incompatible with this module.
       info "esbuild-android-64@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-android-arm64@0.14.38: The platform "linux" is incompatible with this module.
       info "esbuild-android-arm64@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-android-arm64@0.14.38: The CPU architecture "x64" is incompatible with this module.
       info esbuild-darwin-64@0.14.38: The platform "linux" is incompatible with this module.
       info "esbuild-darwin-64@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-darwin-arm64@0.14.38: The platform "linux" is incompatible with this module.
       info "esbuild-darwin-arm64@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-darwin-arm64@0.14.38: The CPU architecture "x64" is incompatible with this module.
       info esbuild-freebsd-64@0.14.38: The platform "linux" is incompatible with this module.
       info "esbuild-freebsd-64@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-freebsd-arm64@0.14.38: The platform "linux" is incompatible with this module.
       info "esbuild-freebsd-arm64@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-freebsd-arm64@0.14.38: The CPU architecture "x64" is incompatible with this module.
       info esbuild-linux-32@0.14.38: The CPU architecture "x64" is incompatible with this module.
       info "esbuild-linux-32@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-linux-arm@0.14.38: The CPU architecture "x64" is incompatible with this module.
       info "esbuild-linux-arm@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-linux-arm64@0.14.38: The CPU architecture "x64" is incompatible with this module.
       info "esbuild-linux-arm64@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-linux-mips64le@0.14.38: The CPU architecture "x64" is incompatible with this module.
       info "esbuild-linux-mips64le@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-linux-ppc64le@0.14.38: The CPU architecture "x64" is incompatible with this module.
       info "esbuild-linux-ppc64le@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-linux-riscv64@0.14.38: The CPU architecture "x64" is incompatible with this module.
       info "esbuild-linux-riscv64@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-linux-s390x@0.14.38: The CPU architecture "x64" is incompatible with this module.
       info "esbuild-linux-s390x@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-netbsd-64@0.14.38: The platform "linux" is incompatible with this module.
       info "esbuild-netbsd-64@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-openbsd-64@0.14.38: The platform "linux" is incompatible with this module.
       info "esbuild-openbsd-64@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-sunos-64@0.14.38: The platform "linux" is incompatible with this module.
       info "esbuild-sunos-64@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-windows-32@0.14.38: The platform "linux" is incompatible with this module.
       info "esbuild-windows-32@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-windows-32@0.14.38: The CPU architecture "x64" is incompatible with this module.
       info esbuild-windows-64@0.14.38: The platform "linux" is incompatible with this module.
       info "esbuild-windows-64@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-windows-arm64@0.14.38: The platform "linux" is incompatible with this module.
       info "esbuild-windows-arm64@0.14.38" is an optional dependency and failed compatibility check. Excluding it from installation.
       info esbuild-windows-arm64@0.14.38: The CPU architecture "x64" is incompatible with this module.
       error globby@12.2.0: The engine "node" is incompatible with this module. Expected version "^12.20.0 || ^14.13.1 || >=16.0.0". Got "12.16.2"
       error Found incompatible module.
       info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
       rake aborted!
       jsbundling-rails: Command build failed, ensure yarn is installed and `yarn build` runs without errors
       /layers/heroku_ruby/gems/vendor/bundle/ruby/3.1.0/gems/jsbundling-rails-1.0.2/lib/tasks/jsbundling/build.rake:5:in `block (2 levels) in <main>'
       Tasks: TOP => assets:precompile => javascript:build
       (See full trace by running task with --trace)

 !
 !     Precompiling assets failed.

What would be best way to update node.js package? I would rather not downgrade any of projects dependencies just to get this working on fly.io.

This deployment is using the Heroku NodeJS buildpack, which may allow you to specify the Node version in your package.json like this:

"engines": {
    "node": "14.x"
  }

Note that you can run fly launch with the latest flyctl which will generate a Dockerfile optimised for deploying modern Rails apps. This way should be faster, and should populate your fly.toml with environment variables you may use to configure things like the Node and Ruby versions.