LoginSignup
0
0

Railsデプロイ時のエラー:error Command "webpack" not found.

Posted at

ElasticBeanstalkでRailsをデプロイ時に遭遇したエラーについて記載します。
誰かのお役に立てれば幸いです。

環境

  • Elastic Beanstalk Ruby 3.6.7@Ruby 3.0 running on 64bit Amazon Linux 2
  • Rails 7.0.4.3
  • bundler_version: 2.2.33
  • rake_version: 13.0.6

エラー内容

[INFO] Running command /bin/su webapp -c bundle exec /opt/elasticbeanstalk/config/private/checkforraketask.rb assets:precompile
[INFO] Found assets:precompile task in Rakefile
[INFO] Running command /bin/su webapp -c bundle exec rake assets:precompile
[INFO] Compiling...
Compilation failed:
yarn run v1.22.19
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command "webpack" not found.

原因

Rails6まではbundle exec rake assets:precompile の実行時に自動で bundle exec rake yarn:install が実行されていましたが、 Rails7 からは実行されなくなったためでした。
これはRails7からWebpackerが標準サポートから外されたためです。そのため今回のエラーはRails6以前からRails7にアップグレードすると発生します。

対応

webpackerがインストールされるようにします。
手順としてはlib/tasks/yarn.rakeを作成して下記の内容を記載します。

Rake::Task["assets:precompile"].enhance [ "yarn:install" ]

ただ、サポートが切れているのでプロジェクトによっては他に移行した方が良いかと思います。

参考

この記事は下記を参考にさせていただきました。ありがとうございました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0