LoginSignup
5
4

More than 3 years have passed since last update.

【Rails Webpacker】Webpacker::MissingEntryErrorのエラーはNode.jsのバージョンに起因するかもしれない話

Posted at

【Rails Webpacker】Webpacker::MissingEntryErrorのエラーはNode.jsのバージョンに起因するかもしれない話

結論から

Nodeのバージョンを13.7以上にしてあげると
app>public>packsが生成され、当該エラーが解決される

解決までのプロセス

普通にrails new appnameでアプリを作成して
コントローラーやモデルの作成を行った後に、ブラウザでアプリをみてみると
このようなエラーが出る時がある。
スクリーンショット 2020-06-27 18.50.26.png

多数のサイトを見て、以下のコマンドを打ってみてもうまくいかない。

terminal
yarn
yarn install
yarn upgrade
brew install yarn
rails install yarn
rails webpacker:install

そして、webpackerのドキュメント READMEを読んでみると以下のコマンドが必要だとのことで、打ってみる

terminal
# こちらの一行はGemfileに書く
gem 'webpacker', '~> 5.x'

gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
yarn add https://github.com/rails/webpacker.git
yarn add core-js regenerator-runtime

このyarn add ~をしたときに、以下のようなエラーが出た。

terminal
error browserslist@4.12.2: The engine “node” is incompatible with this module. Expected version “^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7". Got “13.5.0”

よってnodeのバージョンを13.7以上にしてみた。

まず
インストールできるNode.jsのバージョンを一覧で出力

terminal
nodebrew ls-remote

Node.jsの環境(ディレクトリ構成など)を自動的にセットアップしてくれる「setup」コマンドを実行しておきます

terminal
nodebrew setup

インストールできるNode.jsのバージョンを一覧で出力

terminal
nnodebrew install-binary v13.8.0

特定のバージョンの使用を命令

terminal
nodebrew use v13.8.0

以上によってnodeのバージョンを変えてあげると、当該エラーが消え、うまく画面が表示されるようになった!!

ターミナルを見てみると、

terminal
 Compiled all packs in /Users/nakayama_kazuhito/Desktop/node-version/public/packs

どうやらnodeが結構public直下にある、webpack関連のファイルの生成に関与しているそう。
んーとりあえず、一旦解決!!
またおって原因分析をします!
それではまた!!☺️

5
4
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
5
4