##概要
Rails 5.1 + Vue.js で開発を行う - part1 環境構築を参考にして構築済みのrails環境にvue.jsを追加しようとした。
webpackをインストールするため、$rails webpacker:install
を実行したらコケる現象に遭遇したので一応の解決方法をまとめる。
##環境
- ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin18]
- Rails 5.2.3
- yarn 1.17.3
##rails webpacker:install した時次のエラーが出力される
Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/hoge/projects/testapp/config/webpacker.yml
どうやらtestapp/config配下にwebpacker.ymlがないことが原因らしい。
webpacker.ymlを生成するために$ rails webpacker:install
してるのに....
apple-no-MBP:testapp hoge$ rails webpacker:install
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/twitter-4.8.1/lib/twitter/cursor.rb:51: warning: circular argument reference - collection
Faraday::Builder is now Faraday::RackBuilder.
rails aborted!
Don't know how to build task 'webpacker:install
' (See the list of available tasks with `rails --tasks`)
Did you mean? webpacker:install
webpacker:install:vue
webpacker:install:erb
webpacker:install:elm
webpacker:binstubs
/Users/hoge/projects/testapp/bin/rails:9:in `<top (required)>'
/Users/hoge/projects/testapp/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
(See full trace by running task with --trace)
apple-no-MBP:testapp hoge$ bundle exec rails webpacker:install
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/twitter-4.8.1/lib/twitter/cursor.rb:51: warning: circular argument reference - collection
Faraday::Builder is now Faraday::RackBuilder.
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/twitter-4.8.1/lib/twitter/cursor.rb:51: warning: circular argument reference - collection
Faraday::Builder is now Faraday::RackBuilder.
RAILS_ENV=development environment is not defined in config/webpacker.yml, falling back to production environment
rails aborted!
Webpacker configuration file not found /Users/hoge/projects/testapp/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/hoge/projects/testapp/config/webpacker.yml
/Users/hoge/projects/testapp/config/environment.rb:5:in `<top (required)>'
/Users/hoge/projects/testapp/bin/rails:9:in `<top (required)>'
/Users/hoge/projects/testapp/bin/spring:15:in `require'
/Users/hoge/projects/testapp/bin/spring:15:in `<top (required)>'
./bin/rails:3:in `load'
./bin/rails:3:in `<main>'
Caused by:
Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/hoge/projects/testapp/config/webpacker.yml
/Users/hoge/projects/testapp/config/environment.rb:5:in `<top (required)>'
/Users/hoge/projects/testapp/bin/rails:9:in `<top (required)>'
/Users/hoge/projects/testapp/bin/spring:15:in `require'
/Users/hoge/projects/testapp/bin/spring:15:in `<top (required)>'
./bin/rails:3:in `load'
./bin/rails:3:in `<main>'
Tasks: TOP => app:template => environment
(See full trace by running task with --trace)
apple-no-MBP:testapp hoge$
apple-no-MBP:testapp hoge$
apple-no-MBP:testapp hoge$ bundle exec rails webpacker:install
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/twitter-4.8.1/lib/twitter/cursor.rb:51: warning: circular argument reference - collection
Faraday::Builder is now Faraday::RackBuilder.
/Users/hoge/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/twitter-4.8.1/lib/twitter/cursor.rb:51: warning: circular argument reference - collection
Faraday::Builder is now Faraday::RackBuilder.
RAILS_ENV=development environment is not defined in config/webpacker.yml, falling back to production environment
rails aborted!
Webpacker configuration file not found /Users/hoge/projects/testapp/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/hoge/projects/testapp/config/webpacker.yml
/Users/hoge/projects/testapp/config/environment.rb:5:in `<top (required)>'
/Users/hoge/projects/testapp/bin/rails:9:in `<top (required)>'
/Users/hoge/projects/testapp/bin/spring:15:in `require'
/Users/hoge/projects/testapp/bin/spring:15:in `<top (required)>'
./bin/rails:3:in `load'
./bin/rails:3:in `<main>'
Caused by:Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/hoge/projects/testapp/config/webpacker.yml
/Users/hoge/projects/testapp/config/environment.rb:5:in `<top (required)>'
/Users/hoge/projects/testapp/bin/rails:9:in `<top (required)>'
/Users/hoge/projects/testapp/bin/spring:15:in `require'
/Users/hoge/projects/testapp/bin/spring:15:in `<top (required)>'
./bin/rails:3:in `load'
./bin/rails:3:in `<main>'
Tasks: TOP => app:template => environment
(See full trace by running task with --trace)
##エラー遭遇までに実行したことなど
rails環境にvue.jsを導入する時はたぶん以下の手順が一般的かも
- Gemfileに
gem 'webpacker', github: 'rails/webpacker'
を書き込んで$bundle install
→OK - yarnのインストール。
$ brew install yarn
or$brew upgrade yarn
→OK - webpackerのインストール。
$ rails webpacker:install
→エラー発生
##対処法
$ rails webpacker:install
する前にwebpacker.ymlをつくった。めちゃくちゃ野蛮な解決法。
一応同様のissueはすでに上がっている。
https://github.com/rails/webpacker/issues/940
以下のソースコードをコピペ→config配下にwebpacker.ymlをつくってその中にペースト。
https://raw.githubusercontent.com/rails/webpacker/master/lib/install/config/webpacker.yml
おしまい。たぶんyarnのバージョンが原因な気はしている。
知っている人いたら教えて。