webpacker: heroku: error Command "webpack" not found.

Hello,

I spent the day migrating an old rails 4 app with the gem react_rails to a new rails 5.1 app with webpacker.

Everything works perfectly well, except when I try to deploy the app on heroku.

image

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 44 (14 by maintainers)

Commits related to this issue

Most upvoted comments

@tchret No, I was just checking if thatโ€™s overriding the default one. The default ruby buildpacks now takes care of this with webpacker gem. BTW, could you please add these two buildpacks and try deploying again -

heroku buildpacks:add --index 1 heroku/nodejs
heroku buildpacks:add --index 2 heroku/ruby

I just ran into this in a brand new Rails 6.1.3 app. None of the solutions in this thread worked for me. What did work was adding webpacker to package.json

"dependencies": {
    ...
    "@rails/webpacker": "5.2.1",
    ...
  }

Then I did yarn install and committed the changes in both package.json and yarn.lock. Then I pushed to heroku and deployment worked.

Running heroku buildpacks:add --index 1 heroku/nodejs fixed the error Command "webpack" not found for me.

@tchret The above command wonโ€™t work, try this:

bundle config --delete bin
# Will create yarn binstub
rails app:update:bin
git add bin

@gauravtiwari: haaaa the nodejs one was missing ๐Ÿ˜ƒ I guess it was because the production setup was an old one (created under rails 4)

Thank you so much man ๐Ÿ™๐Ÿผ

Hello ๐Ÿ‘‹ I maintain the Ruby buildpack. The ruby buildpack provides both node and yarn, though you can specify a specific version if you desire by also using the nodejs buildpack.

One thing to watch out for here with this specific error is that the webpack command is provided by your application, usually at bin/webpack. Make sure it is good, you might need to re-generate binstubs:

$ bundle exec rake app:update:bin

Yes, updating a rails app from 6.1 to 7.0 gives the same error, the only thing that seems to work is heroku buildpacks:add --index 1 heroku/nodejs. This is despite having webpack available when I run which webpack in heroku.

Running heroku buildpacks:add --index 1 heroku/nodejs fixed the error Command "webpack" not found for me.

Where did you run that command - from your local terminal, or in heroku?

@schneems : I tried heroku run bash and which webpack and do not see anything . How do I set path on heroku?

Seems like the yarn install task is invoked but there is no yarn binstub present since you were using Rails 4 earlier. Please regenerate them - bundle install --binstubs