webpacker: Command "webpack" not found.

I’m deploying an upgraded Rails 4.x -> 5.1 app to Heroku and am getting the error

Command "webpack" not found.

I’ve gone on to the dyno directly and attempted to run rake assets:precompile which fails with the message:

Webpacker is installed 🎉 🍰
Using /app/config/webpacker.yml file for setting up webpack paths
[Webpacker] Compiling assets 🎉
[Webpacker] Compilation Failed
yarn run v0.22.0
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

error Command "webpack" not found.

This seems to be coming from https://github.com/rails/webpacker/blob/f35331c678c7fd44ef225553629ee3e14989030e/lib/tasks/webpacker/compile.rake#L13

Am I correct in understanding that executing rake assets:precompile is all that needs to occur for a deployment? ie, that handles installing the yarn dependencies etc?

I found that if I do yarn install first and then assets:precompile it works - but I didn’t think I had to do that.

~ $ rake webpacker:verify_install
Webpacker is installed 🎉 🍰
Using /app/config/webpacker.yml file for setting up webpack paths

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 18
  • Comments: 30 (20 by maintainers)

Commits related to this issue

Most upvoted comments

For anyone updating from Rails 4.x to 5.1.x to add yarn binstub -

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

@jnfeinstein Just install webpacker, bundle exec rails webpacker:install. Also you would need to remove ./bin folder from .gitignore

thank you @jakeNiemiec , bundle exec rails webpacker:install adds it to dependencies but I will edit and clearify my comment.

In my case rails webpacker:install was silently ‘failing’. When I check node_modules/.bin folder there was no webpack file and this results in the Command "webpack" not found. error. (webpack source code reference)

After some investigation, I manually tried to add webpack using ~yarn add --dev webpack webpack-dev-server~yarn add webpack webpack-dev-server command and saw the below error(webpack module cant be installed because of some DNS related problem).

error An unexpected error occurred: "https://registry.npmjs.org/webpack: Hostname/IP does not match certificate's altnames: Host: registry.npmjs.org. is not in the cert's altnames: DNS:a.sni.fastly.net, DNS:a.sni.global-ssl.fastly.net".

After some research, the above problem is solved with the command below.

dig https://registry.npmjs.org/webpack @1.1.1.1

Then, I remove node_modules, and generate it once more using bundle exec rails webpacker:install. This time I’ve had node_modules/.bin/webpack file and the error was fixed.

when error happens with capistrano:

before "deploy:assets:precompile", "deploy:yarn_install"

namespace :deploy do
  desc 'Run rake yarn:install'
  task :yarn_install do
    on roles(:web) do
      within release_path do
        execute("cd #{release_path} && yarn install")
      end
    end
  end
end

@ytbryan the buildpack maintainer here. You do not need to use the Node buildpack.

Seems like the task is invoked but there is no yarn binstub present since you were using Rails 4.

screen shot 2017-06-20 at 20 33 27

Please regenerate them - bundle install --binstubs

You need run task yarn install before assets:precompile.

Look at documentation

https://github.com/rails/webpacker/blob/master/docs/deployment.md