13
13

More than 3 years have passed since last update.

rails serverでサーバーを起動しようとしたら、Webpacker configuration file not foundエラーが発生した時の対処方法

Posted at

rails serverでサーバー起動しようとするとエラーが

サーバーを起動するためにコマンドを実行。

$ rails server

すると次のエラーが発生。

(中略)
Webpacker configuration file not found /Users/ユーザ名/app_name/config/webpacker.yml.
Please run rails webpacker:install 
Error: No such file or directory 
@ rb_sysopen - /Users/ユーザ名/app_name/config/webpacker.yml 
(RuntimeError)

解決法

最終的にwebpackerをインストールすることで成功しました。
webpackerのインストールには、Node.jsとYarnのインストールが必要で、これらをインストールした上でwebpackerをインストールすると解決します。

まずはGemfileにwebpackerの記述があるか確認。

Gemfile
gem 'webpacker', '~> 4.0'

bundle installを実行。

$ bundle install

webpackerをインストールしようとするが、Node.jsが必要だと言われる。

$ 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をインストール。

$ brew install node

webpackerをインストールしようとするが、今度はYarnが必要だと言われる。

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

Yarnをインストール。

$ sudo npm install -g yarn
added 1 package in 3.509s

念のためYarnのバージョンを確認。

$ yarn -v
1.22.4

※ここでエラーが出てきた方はこちらの記事を読んでみてください。
yarn -v でYarnのバージョンを確認しようとしたら、Error: EACCES: permission denied, open '/Users/ユーザー名/.config/yarn'と出てくる時の対処法

ちゃんと出てきたので、次はwebpackerのインストール。

$ bundle exec rails webpacker:install

(中略)
Webpacker successfully installed 🎉 🍰

インストールできたので、改めてサーバーを起動。

$ rails s
=> Booting Puma
=> Rails 6.0.2.2 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.3 (ruby 2.6.1-p33), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
Use Ctrl-C to stop

いけました!




参考URL

Rails6でアプリ起動時にWebpacker configuration file not foundエラーが発生した時の対処方法
- https://qiita.com/hasegawa-naoto/items/a2c2900c3f4f05ee3bcb

13
13
0

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
13
13