LoginSignup
2
0

More than 1 year has passed since last update.

Webpacker::Manifest::MissingEntryErrorを解決した話。(Mac ローカルでrails serverの起動編)

Last updated at Posted at 2022-05-28

環境

OS: Mac
SHELL: zsh

Webpacker::Manifest::MissingEntryErrorが出たぞ〜!

ローカル環境で初めてrails serverを実行したら以下のエラーが発生した。

ActionView::Template::Error (Webpacker can't find application.js in /Users/hogehoge/environment/sample_app/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
   unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
):
    2:     <%= csp_meta_tag %>
    3:     <%= stylesheet_link_tag    'application', media: 'all',
    4:                                'data-turbolinks-track': 'reload' %>
    5:     <%= javascript_pack_tag 'application',
    6:                                'data-turbolinks-track': 'reload' %>
  
app/views/layouts/_rails_default.html.erb:5
app/views/layouts/application.html.erb:5

Webpacker can't find application.jsとあるので、webpackerに問題がありそう。

webpackerをコンパイルすんぞ!

そこで、上記の記事を見つけ、コンパイルすればいけそうなので、してみた。

rails webpacker:install
rails webpacker:compile

すると、コンパイルにも失敗してしまう。。。

Compiling...
Compilation failed:
node:internal/crypto/hash:67
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:133:10)
.
.
.

Error: error:0308010C:digital envelope routines::unsupportedという内容で検索すれば、何か出てきそうだな。

Node.jsのバージョンを下げるぞ!

上記の記事から、Node.jsのバージョンをv14.18.1まで下げる必要があるみたい。
(色々やってるうちにできたから、混乱しないようにあえて細かいのは飛ばします。)

$ nodebrew install-binary v14.18.1
Fetching: https://nodejs.org/dist/v14.18.1/node-v14.18.1-darwin-x64.tar.gz
Warning: Failed to create the file 
Warning: /Users/hogehoge/.nodebrew/src/v14.18.1/node-v14.18.1-darwin-x64.ta
Warning: r.gz: No such file or directory
curl: (23) Failure writing output to destination

download failed: https://nodejs.org/dist/v14.18.1/node-v14.18.1-darwin-x64.tar.gz

残念ながら、バージョンを下げることもできない、その程度の人間でした。。。
と思ったら、エラー内容から/Users/hogehoge/.nodebrew/srcまでは用意してあげなくちゃいけないみたい。今回は、
mkdir ~/.nodebrew
mkdir ~/.nodebrew/src
で作りましたが、下記のコードで作成してくれるらしい。
さらに、上記で作ったとしてもこれは必要らしいのでやっとこう。 

$ nodebrew setup    
Fetching nodebrew...
Installed nodebrew in $HOME/.nodebrew

========================================
Export a path to nodebrew:

export PATH=$HOME/.nodebrew/current/bin:$PATH
========================================

そして、リベンジ。

$ nodebrew install v14.18.1       
Fetching: https://nodejs.org/dist/v14.18.1/node-v14.18.1-darwin-x64.tar.gz
######################################################################################################################################### 100.0%
Installed successfully

いけた!

$ node -v
v14.18.1

頼むからコンパイル通ってくれ

イッケーーーーー!!!

$ rails webpacker:compile
.
.
.
[0] (webpack)/buildin/module.js 552 bytes {0} [built]
[1] ./app/javascript/packs/application.js 778 bytes {0} [built]
[5] ./app/javascript/channels/index.js 205 bytes {0} [built]
[6] ./app/javascript/channels sync _channel\.js$ 160 bytes {0} [built]
    + 17 hidden modules

おし!ということは?
スクリーンショット 2022-05-28 16.56.15.png
rails serverが起動した〜!

最後に

今回はrails serverが立ち上がらない事象について、解説しました。
rails tutorialのサンプルアップをローカルに持ってきたらこうなったので、同じ境遇の人がいたら参考にしてください。
また、nodebrew setupを実は飛ばしてて、mkdirだけやっていたので、上で話した以上に苦戦してました。みなさんお気をつけください。

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