かすみん日記

暇なときに何か喋ります

【Rails 6】rails serverでエラーが出る(webpacker)

rails 5系ではふつうに rails server でサーバーが起動していたが、6系にアプデしてからサーバーを起動しようとしたらエラーが出た。

一応解決したのでその作業ログ。

環境

作業ログ

rails s でエラーが出る;

% rails s
=> Booting Puma
=> Rails 6.1.2.1 application starting in development 
=> Run `bin/rails server --help` for more startup options
略
/Users/あ/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/webpacker-5.2.1/lib/webpacker/configuration.rb:99:in `rescue in load': Webpacker configuration file not found /あぷりへのぱす/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/あぷりへのぱす/config/webpacker.yml (RuntimeError)

webpacker が無いらしいのでインストールする。またエラーが出る;

% rails webpacker:install
Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
Exiting!

yarn が必要らしいのでbrewでインストールする;

更新:brewより npm でインストールした方が良いです;

npm install --global yarn

インストールの確認;

% yarn -v
1.22.10

おけ。 もう一度 webpacker のインストールに挑戦する;

rails webpacker:install

多分オーケー。 これで無事railsのサーバーが起動するようになった;

% rails s
=> Booting Puma
=> Rails 6.1.2.1 application starting in development 
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.2.1 (ruby 2.6.6-p146) ("Fettisdagsbulle")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 7966
* Listening on http://127.0.0.1:3000
* Listening on http://[::1]:3000
Use Ctrl-C to stop

以上!

参考

qiita.com

classic.yarnpkg.com