【Rails 6.0】 rails 6.0で`rails s`したら`config/webpacker.yml`がないエラーで怒られた
うぃろぅです。
Railsの教科書の復習のためにrails new
したらrails s
実行時にエラーが出たのでメモ。
確認環境
macで実行。
Rails 6.0がリリースされてた
知らなかった…。
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
がないらしい。
検索したら以下の記事がヒット。
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/ を開いてみる。
やりました。
yarn
がなかったことがそもそもの原因なような気がする。
ではまた。
-
r
をbundle exec rails
としている。↩