Deploying to Heroku: Command "webpack" not found

When I try to deploy to Heroku, I receive this error. Command "webpack" not found. I’ve tried solutions like looking into yarn and installing a package.json in the root. I’m not completely sure but I feel the problem could lie in my package.json needing additional information regarding ‘webpack’.

here is the error in the console:

Rails version :6.0.3.2

Ruby version : 2.7.1

2 Likes

I remember I was fighting with this, but can not remember now how I resolved it. What is your build pack?

Try add a nodeJS buildpack (make sure it is above Ruby buildpack) in Heroku dashboard → your app → Settings → Buildpack

buildpack

6 Likes

Has anyone managed to solve this? I’m having a similar issue locally, yarn install is successful, but webpack is not found when starting rails server.

I’m having this same issue still. I’ve tried adding the build packs, I’ve tried without them. I’ve tried moving dependencies from devDependencies, no dice there either. When I run heroku run bash, and run which webpack, I get nothing. I’m seeing this issue all over github, but no solutions seem to exist that work for everyone.

Hey, I never resolved the issue, just had to recreate the app, copy all the code and try redeploying it. It worked out the second time.

Just thought I’d document what worked for me here.

in package.json

...
  "dependencies": {
    ...
    "@rails/webpacker": "5.1.1",
    ...
  },
...
  "engines": {
    "node": "14.X"
  }
...

I changed my heroku config with this

heroku config:set NPM_CONFIG_PRODUCTION=false YARN_PRODUCTION=false

apparently that keeps some dependencies around for a little longer so that rails can do its thing.

Then I ran into the problem you had. So I added the heroku/nodejs build pack to the build packs as per @soulchild above. (Thanks @soulchild !)

1 Like

These three tips solved the issues for me (upgrading from Rails 5.2.4.5):

  • package.json must contain web packer (see @Wobbles example)
  • Make sure the build packs are configured
  • Run “yarn” locally to update yarn.lock
1 Like

Doing what @soulchild recommended was the thing that fixed for me.

Thanks for the information. I will try to figure it out for more. Keep sharing such informative post keep suggesting such post.

My Lowes Life

I had this problem when upgrading from an older version of Rails. The issue for me was there wasn’t a bin/yarn script. Just generate a new rails project and copy the yarn file across to your site.

As described here

Doing what @Soulchild suggested also helped me with deploying an application with ruby ‘3.0.2’ and ‘rails’, ‘~> 7.0.2.3’

@soulchild’s recommendation also worked, the order of Buildpacks is important (heroku/nodejs) first.