rails: Rails 7 assets:precompile webpack not found
I have a Rails 6.1/Ruby 3.0.3 app where I ran bundle update rails, upgraded yarn versions, and ran rails app:update. This worked fine locally with no issues. I then pushed to production where one of the steps is ‘rails assets:precompile’ This command fails with:
Compiling...
Compilation failed:
yarn run v1.22.17
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command "webpack" not found.
If I revert back to Rails version 6.1.4.4 the command works perfectly fine and compiles assets.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 12
- Comments: 22 (1 by maintainers)
Commits related to this issue
- Maintain Rails < 7 behaviour of running yarn:install before assets:precompile See: https://github.com/rails/rails/issues/43906 — committed to 29th/personnel-v3 by wilson29thid 4 years ago
- Apply webpacker updates Ran `bin/bundler update` and `bin/rails webpacker:install` Per: https://github.com/rails/rails/issues/43906#issuecomment-1094380699 — committed to 29th/personnel-v3 by wilson29thid 4 years ago
- Prepend yarn to precompile task See rails/rails#43906 — committed to asilano/free-dom by asilano 4 years ago
- Update webpacker to get rid of error in render error Command webpack not found. Fix suggested in Rails/Rails: https://github.com/rails/rails/issues/43906#issuecomment-1010987092 — committed to ChaelCodes/MeetAnotherDay by ChaelCodes 3 years ago
- Add yarn as a precompile step according to - https://github.com/rails/rails/issues/43906#issuecomment-1094380699 — committed to ChaelCodes/MeetAnotherDay by ChaelCodes 3 years ago
- Run yarn:install before assets:precompile to work around > error Command "webpack" not found. https://github.com/rails/rails/issues/43906#issuecomment-1099992310 — committed to amatsuda/cfp-app by amatsuda 2 years ago
- Run yarn:install before assets:precompile to work around > error Command "webpack" not found. https://github.com/rails/rails/issues/43906#issuecomment-1099992310 — committed to amatsuda/cfp-app by amatsuda 2 years ago
@bradbajuz was right and this PR, and specifically removing these lines, created this issue.
@chekkan solution worked for me, but the easy fix is to add again this line somewhere in your tasks (ex:
lib/tasks/yarn.rake):I had the same problem deploying rails website using digital ocean app platform after upgrading from version 6 to version 7. Digitalocean app platform uses the heroku buildpacks behind the scene.
Fixed for me by making sure webpacker version
5.4.3was in Gemfile. Made sure to runbin/bundle updatefollowed bybin/rails webpacker:installreviewing the changes carefully.Created
lib/tasks/before/assets_precompile.rakefile.And finally set the environment variable
RAILS_SERVE_STATIC_FILESto true in settings based on the assets pipeline documentation andconfig/environments/production.rbfile.@bradbajuz, I had the same problem here. It seems to be related to
yarn installnot been called https://github.com/heroku/heroku-buildpack-ruby/issues/1240#issuecomment-996885689Instead of add node buildpack I just update the webpacker gem to 6.0.0.rc.6 and it was working again. https://github.com/heroku/heroku-buildpack-ruby/issues/1240#issuecomment-996912552
Maybe upgrading webpacker solves docker as well.
If you’re using heroku, I resolved this by
heroku buildpacks:add --index 1 heroku/nodejsHere is the Dockerfile I am using to create the image:
I then deploy it to kubernetes where I run the image. The part that’s failing is one of my init containers that runs:
RAILS_ENV=production rails assets:precompileThis container fails with the error message.
@MichaelHoste and @chekkan solution worked for me.
For anyone pulling your hair out wondering why the above fixes work for everyone but you (as I’ve been all morning), make sure to use the
.rakefile extension instead of.rb! 🤦🏻♂️@cirdes , package.json and Gemfile.lock state 5.4.3.
I’ll update and report back.
Deployment works on Heroku once I removed yarn (using npm only) and placed the nodejs buildpack in front of the ruby buildpack.
yarn isn’t included anymore in rails as a dependency per this PR. I’m wondering if this change is causing this issue.
I am using docker so that won’t work for me unfortunately. It’s just so strange that I can go back to 6 and everything works.