53
46

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Rails】rails webpacker:install に失敗する場合の対処法

Last updated at Posted at 2019-08-29

##概要
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を導入する時はたぶん以下の手順が一般的かも

  1. Gemfileにgem 'webpacker', github: 'rails/webpacker'を書き込んで$bundle install →OK
  2. yarnのインストール。$ brew install yarn or $brew upgrade yarn →OK
  3. 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のバージョンが原因な気はしている。
知っている人いたら教えて。

53
46
3

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
53
46

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?