Deployment fails for Rails App with App Platform - No such file or directory - /workspace/node_modules/.bin/webpack (Errno::ENOENT)

Hi, as I was deploying rails app on App Platform, I was getting error as followed. Since yarn is already included when I have webpacker gem in the project Gemfile, however, I suspect yarn install was not executed before the out-of-box rake assets:precompile command. So, I’m getting the file not found due to no node_modules being installed.

Cleaning up the bundler cache.
truscan-demo    | 21:33:34 -----> Installing node-v12.16.2-linux-x64
truscan-demo    | 21:33:39 -----> Installing yarn-v1.22.4
truscan-demo    | 21:33:40 -----> Detecting rake tasks
truscan-demo    | 21:34:00 -----> Preparing app for Rails asset pipeline
truscan-demo    | 21:34:00        Running: rake assets:precompile
truscan-demo    | 21:34:23        cd "/workspace" && RAILS_ENV=production bin/webpack
truscan-demo    | 21:34:26        /layers/heroku_ruby/gems/vendor/bundle/ruby/2.6.0/gems/webpacker-3.6.0/lib/webpacker/webpack_runner.rb:11:in `exec': No such file or directory - /workspace/node_modules/.bin/webpack (Errno::ENOENT)
truscan-demo    | 21:34:26              from /layers/heroku_ruby/gems/vendor/bundle/ruby/2.6.0/gems/webpacker-3.6.0/lib/webpacker/webpack_runner.rb:11:in `block in run'
truscan-demo    | 21:34:26              from /layers/heroku_ruby/gems/vendor/bundle/ruby/2.6.0/gems/webpacker-3.6.0/lib/webpacker/webpack_runner.rb:10:in `chdir'
truscan-demo    | 21:34:26              from /layers/heroku_ruby/gems/vendor/bundle/ruby/2.6.0/gems/webpacker-3.6.0/lib/webpacker/webpack_runner.rb:10:in `run'
truscan-demo    | 21:34:26              from /layers/heroku_ruby/gems/vendor/bundle/ruby/2.6.0/gems/webpacker-3.6.0/lib/webpacker/runner.rb:6:in `run'
truscan-demo    | 21:34:26              from bin/webpack:15:in `<main>'
truscan-demo    | 21:34:26        rake aborted!
truscan-demo    | 21:34:26        Command failed with status (1): [cd "/workspace" && RAILS_ENV=production bi...]
truscan-demo    | 21:34:26        /layers/heroku_ruby/gems/vendor/bundle/ruby/2.6.0/gems/react_on_rails-11.1.8/lib/tasks/assets.rake:64:in `block (3 levels) in <top (required)>'
truscan-demo    | 21:34:26        Tasks: TOP => assets:precompile => react_on_rails:assets:compile_environment => react_on_rails:assets:webpack
truscan-demo    | 21:34:26        (See full trace by running task with --trace)
truscan-demo    | 21:34:26 
truscan-demo    | 21:34:26  !
truscan-demo    | 21:34:26  !     Precompiling assets failed.

Note that I have yarn install as build command already. Perhaps it is to run after rake assets:precompeile, but I need it before this rake task. Please help.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

thanks @kamaln7 for the advice. However, this hook was performed after the assets_precompile task still.

I believe react_on_rails overrides the assets_precompile task with its build command. I resolved this by modifying react_on_rails build command, in react_on_rails.rb:

ReactOnRails.configure do |config|
  # This configures the script to run to build the production assets by webpack. Set this to nil
  # if you don't want react_on_rails building this file for you.
  config.build_production_command = "RAILS_ENV=production yarn install && bin/webpack"

I have added yarn install right before the bin/webpack build command. works for me :)

Hi @fung933,

That’s correct, the custom build commands are run at the end of the build, after all the built-in buildpacks have finished processing.

It looks like this issue is specific to the react_on_rails gem which expects yarn install to be run before rake assets:precompile. We’re working on making this work out of the box, but until then, you might be able to use a pre-assets:precompile task to run yarn install (source):

# lib/tasks/before_assets_precompile.rake

task :before_assets_precompile do
  system('yarn install')

# every time you execute 'rake assets:precompile'
# run 'before_assets_precompile' first    
Rake::Task['assets:precompile'].enhance ['before_assets_precompile']

I’m not familiar enough with rake myself so I don’t know if this will work with the current versions of rake.