title: Webpack error when deploying Rails 6 app on elastic beanstalk with npm, yarn and webpack
body: <p>I tried to deploy my Rails 6 app that's running stable on production (!) into a second new environment on elastic beanstalk (eb) and I cannot get it to run despite just copying the configuration from the first setup.</p>
  
  <p>After researching all resources I could find for 2 days, I'm currently stuck with the following error <code>compilation failed: webpack not installed</code>:</p>
  
  <pre><code>-------------------------------------
  /var/log/eb-activity.log
  -------------------------------------
    +++ export RUBY_VERSION=2.6.5
    +++ RUBY_VERSION=2.6.5
    +++ export GEM_ROOT=/opt/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0
    +++ GEM_ROOT=/opt/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0
    ++ ((  0 != 0  ))
    + /opt/elasticbeanstalk/support/scripts/check-for-gem.rb puma
    + echo true
  [2020-01-09T20:22:02.966Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/AppDeployPreHook] : Completed activity. Result:
    Successfully execute hooks in directory /opt/elasticbeanstalk/hooks/appdeploy/pre.
  [2020-01-09T20:22:02.966Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild] : Starting activity...
  [2020-01-09T20:22:10.381Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Starting activity...
  [2020-01-09T20:22:10.462Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_XXX] : Starting activity...
  [2020-01-09T20:22:23.059Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_XXX/Command 01_restart_nginx] : Starting activity...
  [2020-01-09T20:22:24.293Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_XXX/Command 01_restart_nginx] : Completed activity. Result:
    nginx: [warn] conflicting server name "_" on 0.0.0.0:80, ignored
    nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
    nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
    Stopping nginx: [  OK  ]
    Starting nginx: nginx: [warn] conflicting server name "_" on 0.0.0.0:80, ignored
    nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
    nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
    [  OK  ]
  
  [2020-01-09T20:22:24.293Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_XXX] : Completed activity.
  [2020-01-09T20:22:24.375Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_XXX] : Starting activity...
  [2020-01-09T20:22:37.045Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_XXX/Command 10_install_webpack] : Starting activity...
  [2020-01-09T20:25:12.155Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_XXX/Command 10_install_webpack] : Completed activity. Result:
    npm notice created a lockfile as package-lock.json. You should commit this file.
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
  
    + webpack@4.41.5
    added 322 packages from 197 contributors and audited 4227 packages in 144.209s
  
    3 packages are looking for funding
    run `npm fund` for details
  
    found 0 vulnerabilities
  
  
  [2020-01-09T20:25:13.256Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_XXX/Command 11_precompile] : Starting activity...
  [2020-01-09T20:30:24.349Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_XXX/Command 11_precompile] : Activity execution failed, because: yarn install v1.21.1
    warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
    [1/4] Resolving packages...
    [2/4] Fetching packages...
    info fsevents@1.2.9: The platform "linux" is incompatible with this module.
    info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
    [3/4] Linking dependencies...
    [4/4] Building fresh packages...
    success Saved lockfile.
    Done in 162.47s.
    yarn install v1.21.1
    warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
    [1/4] Resolving packages...
    [2/4] Fetching packages...
    info fsevents@1.2.9: The platform "linux" is incompatible with this module.
    info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
    [3/4] Linking dependencies...
    [4/4] Building fresh packages...
    Done in 83.51s.
    I, [2020-01-09T20:29:36.608192 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/manifest-cadda289ef9c70eaa0879a36e6263cb33f7523a16b3ef862e0b8609cdc2bdab1.js
    I, [2020-01-09T20:29:36.609243 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/manifest-cadda289ef9c70eaa0879a36e6263cb33f7523a16b3ef862e0b8609cdc2bdab1.js.gz
    I, [2020-01-09T20:29:36.609422 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-c0be3de839559053bb0a9486d5645ccba7a7452f6ef0370ee498e1fa59e364b2.png
    I, [2020-01-09T20:29:36.609592 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-469a46bb9645a42d499c7f74ee69ffad4176e08c4373b6fe67a418e8289f3d83.png
    I, [2020-01-09T20:29:36.609775 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-e57001fd85a8e1f4da2bb4bbd309a7d880a9d18e3447d743190ff9befb86413f.jpg
    I, [2020-01-09T20:29:36.610062 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/application-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css
    I, [2020-01-09T20:29:36.610155 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/application-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css.gz
    I, [2020-01-09T20:29:36.610249 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/wall_street-e57001fd85a8e1f4da2bb4bbd309a7d880a9d18e3447d743190ff9befb86413f.jpg
    I, [2020-01-09T20:29:36.610500 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/asset-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css
    I, [2020-01-09T20:29:36.610582 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/asset-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css.gz
    I, [2020-01-09T20:29:36.690087 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css
    I, [2020-01-09T20:29:36.690356 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css.gz
    I, [2020-01-09T20:29:36.690743 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/main-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css
    I, [2020-01-09T20:29:36.690957 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/main-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css.gz
    I, [2020-01-09T20:29:36.691548 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/round-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css
    I, [2020-01-09T20:29:36.772944 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/round-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css.gz
    Compiling...
    Compilation failed:
  
    webpack not installed
  
    Install webpack to start bundling: [32m
    $ npm install --save-dev webpack
  
  
     (ElasticBeanstalk::ExternalInvocationError)
  
  
  [2020-01-09T20:30:24.349Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_XXX/Command 11_precompile] : Activity failed.
  [2020-01-09T20:30:24.349Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_1_XXX] : Activity failed.
  [2020-01-09T20:30:24.349Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Activity failed.
  [2020-01-09T20:30:25.008Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0/EbExtensionPostBuild] : Activity failed.
  [2020-01-09T20:30:25.008Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11/AppDeployStage0] : Activity failed.
  [2020-01-09T20:30:25.009Z] INFO  [1508]  - [Application update app-f4fb-200109_211455@11] : Completed activity. Result:
    Application update - Command CMD-AppDeploy failed
  [2020-01-09T20:36:59.175Z] INFO  [5013]  - [CMD-TailLogs] : Starting activity...
  [2020-01-09T20:36:59.175Z] INFO  [5013]  - [CMD-TailLogs/AddonsBefore] : Starting activity...
  [2020-01-09T20:36:59.175Z] INFO  [5013]  - [CMD-TailLogs/AddonsBefore] : Completed activity.
  [2020-01-09T20:36:59.175Z] INFO  [5013]  - [CMD-TailLogs/TailLogs] : Starting activity...
  [2020-01-09T20:36:59.175Z] INFO  [5013]  - [CMD-TailLogs/TailLogs/TailLogs] : Starting activity...
  
  -------------------------------------
  /var/log/eb-commandprocessor.log
  -------------------------------------
  [2020-01-09T20:15:53.363Z] DEBUG [1508]  : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||_API||_Commands..
  [2020-01-09T20:15:53.364Z] INFO  [1508]  : Found enabled addons: ["logpublish", "logstreaming"].
  [2020-01-09T20:15:53.444Z] INFO  [1508]  : Updating Command definition of addon logpublish.
  [2020-01-09T20:15:53.444Z] INFO  [1508]  : Updating Command definition of addon logstreaming.
  [2020-01-09T20:15:53.444Z] DEBUG [1508]  : Retrieving metadata for key: AWS::CloudFormation::Init||Infra-WriteApplication2||files..
  [2020-01-09T20:15:53.445Z] DEBUG [1508]  : Retrieving metadata for key: AWS::ElasticBeanstalk::Ext||ManifestFileS3Key..
  [2020-01-09T20:15:56.071Z] INFO  [1508]  : Loading manifest from bucket 'elasticbeanstalk-eu-west-1-511205900284' using computed S3 key 'resources/environments/e-zcsy2pgich/_runtime/versions/manifest_1578600905237'.
  [2020-01-09T20:15:56.520Z] INFO  [1508]  : Updated manifest cache: deployment ID 11 and serial 18.
  [2020-01-09T20:15:56.520Z] DEBUG [1508]  : Loaded definition of Command CMD-AppDeploy.
  [2020-01-09T20:15:56.520Z] INFO  [1508]  : Executing Application update
  [2020-01-09T20:15:56.520Z] INFO  [1508]  : Executing command: CMD-AppDeploy...
  [2020-01-09T20:15:56.520Z] INFO  [1508]  : Executing command CMD-AppDeploy activities...
  [2020-01-09T20:15:56.520Z] DEBUG [1508]  : Setting environment variables..
  [2020-01-09T20:15:56.520Z] INFO  [1508]  : Running AddonsBefore for command CMD-AppDeploy...
  [2020-01-09T20:15:59.632Z] DEBUG [1508]  : Running stages of Command CMD-AppDeploy from stage 0 to stage 1...
  [2020-01-09T20:15:59.632Z] INFO  [1508]  : Running stage 0 of command CMD-AppDeploy...
  [2020-01-09T20:15:59.632Z] INFO  [1508]  : Running leader election...
  [2020-01-09T20:16:07.059Z] INFO  [1508]  : Instance is Leader.
  [2020-01-09T20:16:07.059Z] DEBUG [1508]  : Loaded 5 actions for stage 0.
  [2020-01-09T20:16:07.059Z] INFO  [1508]  : Running 1 of 5 actions: DownloadSourceBundle...
  [2020-01-09T20:16:14.038Z] INFO  [1508]  : Running 2 of 5 actions: EbExtensionPreBuild...
  [2020-01-09T20:18:12.566Z] INFO  [1508]  : Running 3 of 5 actions: AppDeployPreHook...
  [2020-01-09T20:22:02.966Z] INFO  [1508]  : Running 4 of 5 actions: EbExtensionPostBuild...
  [2020-01-09T20:30:25.008Z] ERROR [1508]  : Command execution failed: Activity failed. (ElasticBeanstalk::ActivityFatalError)
  caused by: yarn install v1.21.1
    warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
    [1/4] Resolving packages...
    [2/4] Fetching packages...
    info fsevents@1.2.9: The platform "linux" is incompatible with this module.
    info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
    [3/4] Linking dependencies...
    [4/4] Building fresh packages...
    success Saved lockfile.
    Done in 162.47s.
    yarn install v1.21.1
    warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
    [1/4] Resolving packages...
    [2/4] Fetching packages...
    info fsevents@1.2.9: The platform "linux" is incompatible with this module.
    info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
    [3/4] Linking dependencies...
    [4/4] Building fresh packages...
    Done in 83.51s.
    I, [2020-01-09T20:29:36.608192 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/manifest-cadda289ef9c70eaa0879a36e6263cb33f7523a16b3ef862e0b8609cdc2bdab1.js
    I, [2020-01-09T20:29:36.609243 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/manifest-cadda289ef9c70eaa0879a36e6263cb33f7523a16b3ef862e0b8609cdc2bdab1.js.gz
    I, [2020-01-09T20:29:36.609422 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-c0be3de839559053bb0a9486d5645ccba7a7452f6ef0370ee498e1fa59e364b2.png
    I, [2020-01-09T20:29:36.609592 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-469a46bb9645a42d499c7f74ee69ffad4176e08c4373b6fe67a418e8289f3d83.png
    I, [2020-01-09T20:29:36.609775 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-e57001fd85a8e1f4da2bb4bbd309a7d880a9d18e3447d743190ff9befb86413f.jpg
    I, [2020-01-09T20:29:36.610062 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/application-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css
    I, [2020-01-09T20:29:36.610155 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/application-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css.gz
    I, [2020-01-09T20:29:36.610249 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-e57001fd85a8e1f4da2bb4bbd309a7d880a9d18e3447d743190ff9befb86413f.jpg
    I, [2020-01-09T20:29:36.610500 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/asset-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css
    I, [2020-01-09T20:29:36.610582 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/asset-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css.gz
    I, [2020-01-09T20:29:36.690087 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css
    I, [2020-01-09T20:29:36.690356 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/XXX-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css.gz
    I, [2020-01-09T20:29:36.690743 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/main-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css
    I, [2020-01-09T20:29:36.690957 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/main-e18be23bdc9236e71700193c31376705b918eab0738fdd68ef83e572da76c13d.css.gz
    I, [2020-01-09T20:29:36.691548 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/round-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css
    I, [2020-01-09T20:29:36.772944 #2970]  INFO -- : Writing /var/app/ondeck/public/assets/round-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css.gz
    Compiling...
    Compilation failed:
  
    webpack not installed
  
    Install webpack to start bundling: [32m
    $ npm install --save-dev webpack
  
  
     (ElasticBeanstalk::ExternalInvocationError)
  
  
  [2020-01-09T20:30:25.009Z] ERROR [1508]  : Command CMD-AppDeploy failed!
  [2020-01-09T20:30:25.086Z] INFO  [1508]  : Command processor returning results: 
  {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"(TRUNCATED)...NFO -- : Writing /var/app/ondeck/public/assets/round-d0ff5974b6aa52cf562bea5921840c032a860a91a3512f7fe8f768f6bbe005f6.css.gz\nCompiling...\nCompilation failed:\n\nwebpack not installed\n\nInstall webpack to start bundling: \u001b[32m\n$ npm install --save-dev webpack. \ncontainer_command 11_precompile in .ebextensions/yarn.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI","returncode":1,"events":[]}],"truncated":"true"}
  
  </code></pre>
  
  <p>Logically, I tried to install webpack again and again which should be normally already be done through the ebextensions file <code>yarn.config</code>:</p>
  
  <pre><code>commands:
    # 01_remove_clean_and_install_latest_nodejs:
      # run this command from /tmp directory
      # cwd: /tmp
      # test: '[ -f /usr/bin/node ] &amp;&amp; echo "remove previous node"'
      # command: 'sudo yum remove -y nodejs | sudo rm /etc/yum.repos.d/nodesource*'
  
    02_node_get:
      # run this command from /tmp directory
      cwd: /tmp
      # flag -y for no-interaction installation
      command: 'sudo curl --silent --location https://rpm.nodesource.com/setup_13.x | sudo bash -'
  
    03_node_install:
      # run this command from /tmp directory
      cwd: /tmp
      command: 'sudo yum -y install nodejs'
  
    04_yarn_get:
      # run this command from /tmp directory
      cwd: /tmp
      # don't run the command if yarn is already installed (file /usr/bin/yarn exists)
      test: '[ ! -f /usr/bin/yarn ] &amp;&amp; echo "yarn not installed"'
      command: 'sudo wget https://dl.yarnpkg.com/rpm/yarn.repo -O /etc/yum.repos.d/yarn.repo'
  
    05_yarn_install:
      # run this command from /tmp directory
      cwd: /tmp
      test: '[ ! -f /usr/bin/yarn ] &amp;&amp; echo "yarn not installed"'
      command: 'sudo yum -y install yarn'
  
    06_mkdir_webapp_dir:
      command: mkdir /home/webapp
      ignoreErrors: true
  
    07_chown_webapp_dir:
      command: chown webapp:webapp /home/webapp
      ignoreErrors: true
  
    08_chmod_webapp_dir:
      command: chmod 700 /home/webapp
      ignoreErrors: true
  
    09_update_bundler:
      command: gem update bundler
      ignoreErrors: true
  
  container_commands:
  
    10_install_webpack:
      command: "sudo npm install --save-dev webpack"
  
    11_precompile:
      command: "bundle exec rake assets:precompile"
  </code></pre>
  
  <p>My other settings are <code>RAILS_SKIP_ASSET_COMPILATION=true</code> in eb</p>
  
  <p>I tried installing webpack manually after ssh-ing into the machine via npm and yarn, with and without sudo, but nothing worked...</p>
  
  <p>Each <code>eb deploy</code> takes roughly 20 mins and then times out into a "severe" state with the above error.</p>
  
  <h2>Edit</h2>
  
  <p>For some weird reason I got it to work now by running <code>bundle exec rails webpacker:install</code> in addition to having it in the Gemfile. Still not comfortable with the setup, but at least it's working for now</p>