1
0

More than 1 year has passed since last update.

Railsでアプリ作成時のMySQLエラーの解消方法

Posted at

動作環境

M1 macboook pro
macOS Monterey ver.12.5

1. opensslの再設定

rails new (アプリ名) -d mysqlを実行すると、以下のエラーが発生。

An error occurred while installing mysql2 (0.5.4), and Bundler cannot continue.

macOSのSierra以降は、opensslがデフォルトが変わっているようで、以下のように再度インストール。

% brew install openssl
% bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"

そして、改めてbundle installを実行。

% bundle install

2. railsサーバが起動しない

opensslの設定後、今度は、rails sでサーバが起動せず、以下のエラーが発生。

=> Run `bin/rails server --help` for more startup options
Exiting
/Users/arakijun/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/webpacker-5.4.3/lib/webpacker/configuration.rb:103:in `rescue in load': Webpacker configuration file not found /Users/arakijun/Desktop/rails6_mysql_app/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/arakijun/Desktop/rails6_mysql_app/config/webpacker.yml (RuntimeError)

エラー文の中にPlease run rails webpacker:installとあるため、以下の通りに実行。

$ bundle exec rails webpacker:install

これでOKです!

1
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
1
0