うぃろぅ.log

140字で綴りきれない日々の徒然備忘録

【Rails 6.0】 rails 6.0で`rails s`したら`config/webpacker.yml`がないエラーで怒られた

うぃろぅです。

igarashikuniaki.net

Railsの教科書の復習のためにrails newしたらrails s実行時にエラーが出たのでメモ。

確認環境

macで実行。

Rails 6.0がリリースされてた

weblog.rubyonrails.org

知らなかった…。

rails newして生成されたGemfileが以下のようになっていた。

source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "2.6.3"

# Bundle edge Rails instead: gem "rails", github: "rails/rails"
gem "rails", "~> 6.0.0"
# Use sqlite3 as the database for Active Record
gem "sqlite3", "~> 1.4"
# Use Puma as the app server
gem "puma", "~> 3.11"
# Use SCSS for stylesheets
gem "sass-rails", "~> 5"
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem "webpacker", "~> 4.0"
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem "turbolinks", "~> 5"
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem "jbuilder", "~> 2.7"
# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"
# Use Active Model has_secure_password
# gem "bcrypt", "~> 3.1.7"

# Use Active Storage variant
# gem "image_processing", "~> 1.2"

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", ">= 1.4.2", require: false

group :development, :test do
  # Call "byebug" anywhere in the code to stop execution and get a debugger console
  gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling "console" anywhere in the code.
  gem "web-console", ">= 3.3.0"
  gem "listen", ">= 3.0.5", "< 3.2"
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem "spring"
  gem "spring-watcher-listen", "~> 2.0.0"
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem "capybara", ">= 2.15"
  gem "selenium-webdriver"
  # Easy installation and use of web drivers to run system tests with browsers
  gem "webdrivers"
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]

最初に気づいたのはgem "chrome-driver"gem "webdrivers"になったので警告されることがなくなったこと。

rails sでエラー

で、rails sしてみたらエラー。

以下のように出力されている。

1: from /Users/vviilloovv/Git/rails/books-app/vendor/bundle/ruby/2.6.0/gems/webpacker-4.0.7/lib/webpacker/configuration.rb:87:in `load'
/Users/vviilloovv/Git/rails/books-app/vendor/bundle/ruby/2.6.0/gems/webpacker-4.0.7/lib/webpacker/configuration.rb:91:in `rescue in load': Webpacker configuration file not found /Users/vviilloovv/Git/rails/books-app/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/vviilloovv/Git/rails/books-app/config/webpacker.yml (RuntimeError)

RuntimeErrorで落ちている。config/webpacker.ymlがないらしい。

検索したら以下の記事がヒット。

qiita.com

rails webpacker:installを実行すればいいとのこと。
実行してみた1

r webpacker:install
Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/

yarnがないって怒られる。
Homebrewでyarnをインストール。

❯ brew install yarn
(中略)
==> Summary
🍺  /usr/local/Cellar/node/12.8.1: 4,629 files, 53.1MB
==> Installing yarn
==> Downloading https://yarnpkg.com/downloads/1.17.3/yarn-v1.17.3.tar.gz
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/49970642/114f8b80-a477-11e9
######################################################################## 100.0%

OK。
もう一回rails webpacker:installする。

r webpacker:install
RAILS_ENV=development environment is not defined in config/webpacker.yml, falling back to production environment
      create  config/webpacker.yml
(中略)
✨  Done in 10.69s.
Webpacker successfully installed 🎉 🍰

できたっぽい。
改めてrails sを実行してみる。

r s
=> Booting Puma
=> Rails 6.0.0 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.3-p62), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop

OK。

http://localhost:3000/ を開いてみる。

f:id:vviilloovv:20190817182235p:plain

やりました。

yarnがなかったことがそもそもの原因なような気がする。

ではまた。


  1. rbundle exec railsとしている。