archive
Railsサーバーを立てるときにエラーが出る
Railsサーバーを立てようとしたときにエラーが出てしまったのでその解決法です。
こちらを参照にしてrails開発環境の構築をトライ。
LINK:https://prog-8.com/docs/rails-env
Railsサーバーを立てるため、下記を入力。
`$ Rails S`
すると下記のようなエラーが。
` Webpacker configuration file not found /Users/shotarokamimura/tweet_app/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - `
ググってみると、rails 6の開発環境にはwebpackerとyarnのインストールが必要とのこと。
参照:https://qiita.com/NaokiIshimura/items/8203f74f8dfd5f6b87a0
なのでまずはwebpackerをインストール。
`$ 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をまずインストールする必要があるらしい。
指示された通りに、https://nodejs.org/en/download/へ移動する。

ダウンロードして、再度webpackerをインストール。
すると次のエラー。
`Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/`
Yarnをインストール。
`$ brew install yarn`
すると次のエラーが。
`Error: The following directories are not writable by your user: /usr/local/include /usr/local/libYou should change the ownership of these directories to your user. sudo chown -R $(whoami) /usr/local/include /usr/local/lib`
なので指示通り、以下を実行
` $ sudo chown -R $(whoami) /usr/local/include /usr/local/lib`
再度yarnをインストールを実行するとできた。
yarnがインストールできてるかは下記で確認できる。
`$ yarn -v`
なのでwebpackerを再度インストール。
`$ rails webpacker:install `
今度は完了。
順番的にはyarn→webpackerの順番でインストールする必要があるらしい。
再度、rails s をlocalhost:3000を確認すると、下記の画面が無事に出てきた。
