shakapacker: Bump from v6.5.5 to v6.5.6 caused `error Command "webpack" not found.`

Started seeing the error after upgrading from v6.5.5 to v6.5.6. Reversing fixed the issue.

Expected behavior:

Assets compilation to complete without errors

Actual behavior:

Failure to complete assets:precompile on production.

...suppressed output....
Writing pagy-module.d-2ae43d1f2559cebcbe95eeb7b90519fdd958ee79.ts"

I, [2023-02-14T14:29:14.566397 #7] INFO -- : Compiling...
E, [2023-02-14T14:29:15.520103 #7] ERROR -- :
COMPILATION FAILED:
EXIT STATUS: pid 21 exit 1
OUTPUTS:
yarn run v1.22.19
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command "webpack" not found.

Small, reproducible repo:

Setup environment:

  • Ruby version: 3.1.2
  • Rails version: 7.0.4.2
  • Shakapacker version: 6.5.5
  • yarn packages are installed automatically

Could this be related to an outdated binstub? Running rails webpacker:install locally again

Copying binstubs
       exist    bin
    conflict    bin/webpacker
  Overwrite /bin/webpacker? (enter "h" for help) [Ynaqdhm] d
    #!/usr/bin/env ruby
    
  - require "pathname"
  + ENV["RAILS_ENV"] ||= "development"
  + ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
  + 
    require "bundler/setup"
    require "webpacker"
    require "webpacker/webpack_runner"
  - 
  - ENV["RAILS_ENV"] ||= "development"
  - ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)
    
    APP_ROOT = File.expand_path("..", __dir__)
    Dir.chdir(APP_ROOT) do
      Webpacker::WebpackRunner.run(ARGV)
    end
  Retrying...

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 6
  • Comments: 15 (10 by maintainers)

Most upvoted comments

@Alex-450 my setup is currently relying on executing yarn install only when assets:precompile is executed.
I’ll probably add a step to execute the install anyway, since shakapacker version 7 will no longer execute it with the precompile step.

Was having the same issue and fixed by adding yarn install --frozen-lockfile --immutable to the node setup, as setup-node doesn’t cache node_modules.

Not sure if this is also relevant for you @raivil

@justin808 Just switched the buildpack order (with node before ruby) and can confirm it successfully built with 6.6.0.

AFAIK, the heroku/nodejs build pack installs yarn dependencies.

Maybe you have the nodejs buildpack AFTER the ruby. If so, you’ll get the error above, as precompile runs as part of the ruby buildpack.

@ahangarha we probably need to document this.

@justin808 it runs on Docker (ruby:3.1.2-bullseye). Some relevant of the commands on docker file are

RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && apt-get install -y nodejs && npm install --global yarn

RUN gem update --system && gem install bundler -v 2.3.18 --no-document \
    && bundle config --local build.pg --with-pg-config=/usr/bin/pg_config \
    && bundle config set without 'test development' \
    && bundle config set deployment 'true' \
    && bundle install --jobs 5

RUN bundle check || bundle package --all || bundle install --local

npm packages are installed when doing assets precompile. And this is not happening on 6.5.6, only on 6.5.5.

I know this behavior will be deprecated in shakapacker 7, since the warning is pretty clear.

$ bundle exec rails assets:precompile
Shakapacker - Automatic installation of yarn packages is deprecated
Automatic installation of yarn packages when assets are precompiled is deprecated and will be removed in Shakapacker v7.
Please ensure you are installing yarn packages explicitly before the asset compilation.