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 3 years ago
- Reactions: 8
- 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 2 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 2 years ago
- Prepend yarn to precompile task See rails/rails#43906 — committed to asilano/free-dom by asilano 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.3
was in Gemfile. Made sure to runbin/bundle update
followed bybin/rails webpacker:install
reviewing the changes carefully.Created
lib/tasks/before/assets_precompile.rake
file.And finally set the environment variable
RAILS_SERVE_STATIC_FILES
to true in settings based on the assets pipeline documentation andconfig/environments/production.rb
file.@bradbajuz, I had the same problem here. It seems to be related to
yarn install
not 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/nodejs
Here 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:precompile
This container fails with the error message.
@MichaelHoste and @chekkan solution worked for me.
@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.
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.