16
2

More than 1 year has passed since last update.

Webpacker::Manifest::MissingEntryError 解消法 - Rails version 6.0 環境

Last updated at Posted at 2022-07-11

対象環境

node.js : v16.x.x
rails : v6.0.x

具体的なエラー前動作

terminal
rails new xxx
cd xxx
rails g scaffold user
rails db:create
rails db:migrate
rails s

として、
http://localhost:3000/users
にアクセスすると下記のエラーが発生

Screen Shot 2022-07-11 at 11.58.43.png

対処法【下記いずれかの対応で対処可能です】

1.railsのバージョンを6.1.xに変更する(推奨)

参考:
コマンド
インストール可能なバージョン参照

2.webpackerのバージョンを5に変更する

Gemfile
変更前: gem 'webpacker', '~> 4.0'
変更後: gem 'webpacker', '~> 5.0'

に変更後

terminal
bundle install
rails webpacker:install
rails webpacker:compile

3.node.jsのバージョンをv14,又はv12にダウングレードする

原因

実は、ターミナルでrails newした時に下記のエラーが発生している

terminal
rails new xxx
(省略)
1 error generated.
make: *** [Release/obj.target/binding/src/binding.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/motoya/study/rails_6.0.3/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Darwin 21.5.0
gyp ERR! command "/Users/motoya/.nvm/versions/node/v16.15.1/bin/node" "/Users/motoya/study/rails_6.0.3/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/motoya/study/rails_6.0.3/node_modules/node-sass
gyp ERR! node -v v16.15.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
Build failed with error code: 1
(省略)

端的に理解したところでは、
『node -v v16.15.1 & node-gyp -v v3.8.0のため、buildに失敗してます』
ということなので、依存関係が崩れているためエラーが発生しております。
※恐らく、webpacker v4のnode-gyp用の表記が古く現バージョンでは実行できないコマンドが表記されていると推察

この依存関係の崩れを修正するために

  1. node -v v16.15.1 & node-gyp -v v3.8.0で実行可能な状態にする
    Lrailsのバージョンを6.1.xに変更する
    Lwebpackerのバージョンを5に変更する

  2. webpacker v4でも読み込めるようにnodeのバージョンを下げる
    Lnode.jsのバージョンをv14,又はv12にダウングレードする

を実施することで原因を取り除けるということです。

最後に

表層の原因と解決方法は理解できましたが、
・webpackerとnode_modulesの関係
・node.jsとnode-gypのバージョン関係
等々、深層部の理解に詰まったので今後調査していきたいと思います。
※ご教授いただけるととても嬉しいです(>_<)

16
2
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
16
2