51
42

More than 3 years have passed since last update.

Rails6が立ち上がらない!Node.js, webpacker, yarnのインストール 【開発日記】薬価検索アプリno.5-2

Last updated at Posted at 2019-10-31

出来上がりのサイト

薬価検索アプリmedipraはこちらです
→ 見に行ってみる

2020/04/12更新

ブログの方に移動しました
→ こちら

前回の内容はこちら。

【開発日記】薬価検索アプリno.5 〜Railsでアプリケーションの雛形作成、mySQLエラー、GitHubの設定まで〜

開発背景などはこちら

【開発日記】薬価検索アプリno.1 〜開発概要→企画〜

現在の進捗状況

1.必要な機能の洗い出し
2.必要な画面設計
3.データベース設計
4.Railsでアプリケーションの雛形作成 ⬅︎今ココ
5.大きな機能から順に実装 
6.テストコードを書いて動作を担保する
7.リファクタリングして整理する
8.デプロイ

rails sしてみたら...

前回、 rails new してアプリケーションの雛形を作りました。
そのまま勢いでrails sしたのですが...

=> Booting Puma
=> Rails 6.0.0 application starting in development 
=> Run `rails server --help` for more startup options
RAILS_ENV=development environment is not defined in config/webpacker.yml, falling back to production environment
Exiting
Traceback (most recent call last):
    68: from bin/rails:4:in `<main>'

#中略

2: from /Users/user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/webpacker-4.0.7/lib/webpacker/configuration.rb:84:in `data'
     1: from /Users/user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/webpacker-4.0.7/lib/webpacker/configuration.rb:87:in `load'
/Users/user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/webpacker-4.0.7/lib/webpacker/configuration.rb:91:in `rescue in load': Webpacker configuration file not found /Users/user/projects/medipra/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/user/projects/medipra/config/webpacker.yml (RuntimeError)

と、エラーが出てしまいました。

Rails6からの変更点

完全に僕の勉強不足なのですが、
Rails6から標準でwebpackを利用する ようになっています。

エラー文に rails webpacker:install を実行しろとあるのでやってみます。

Node.js, webpacker, yarnのインストール

$ rails webpacker:install

=>
sh: node: command not found
sh: nodejs: command not found
Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/

今度はnode.jsを入れろと言われてしまいました。

Homebrewを使ってインストールします。

$ brew install node

Node.jsがインストールできたら次のコマンドで確認しましょう

$ node -v
=>v12.12.0

ちゃんとインストールされたことが確認できました。

ではもう一回webpackerをインストールします。

$ rails webpacker:install
=>Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/

今度はyarnがないと叱られてしまいました。

調べてみるとyarnはNode.jsの環境で使うパッケージマネージャー。Rubyで言う所のbundlerのようなものでしょうか。

またhomebrewを使ってインストールします。

$ brew install yarn

完了したら、確認してみます。

$ yarn -v
=> 1.19.1

ではもう一回webpackerをば。

$ rails webpacker:install

こんなのが出れば完了です!
Image from Gyazo

これでrails s入れたらおなじみの画面が表示されました。

めでたしめでたし。

まとめ・所感

新しく出たRails6を使いたいがばかりに見切り発車してしまいましたが、大きな仕様変更を確認していなかった自分の勉強不足ですね。

こちらの雑誌にもしっかり掲載されていました。
しっかり勉強します!
amazonへのリンク(アフィリエイトではないです)
https://www.amazon.co.jp/gp/product/4297108690/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1

最後までお付き合いいただきありがとうございました。

51
42
2

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
51
42