1
0

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 3 years have passed since last update.

EC2で古いバージョンのnode.jsを最新バージョンにする

Posted at

ポートフォリオの作成がひと段落ついたのでAWSにデプロイしようとしたところ、node.jsの設定でどハマりしたので皆さんに情報共有していこうと思います。

#事象
以下の記事を参考にAWSで通常デプロイに挑戦しました。

【画像付きで丁寧に解説】AWS(EC2)にRailsアプリをイチから上げる方法↓
https://qiita.com/Yuki_Nagaoka/items/975b7598806d6ae0c0b2

こちらの記事を参考にRailsアプリの公開編まではスムーズにいきアプリの公開をしてみたのですがurlを入力してみたところ「このサイトにアクセスできません」と表示され・・・

#ログを調べてみると
EC2インスタンスに繋がった状態で以下のコマンドを実行しログファイルを参照

EC2.
[daiki@ip-10-0-0-56 log]$ tail -n 30 production.log
F, [2020-10-12T13:28:37.845307 #22722] FATAL -- : [66518e09-a517-412e-8f3c-97c588a4b2f1] ActionView::Template::Error (The asset "homes.css" is not present in the asset pipeline.
):
F, [2020-10-12T13:28:37.845424 #22722] FATAL -- : [66518e09-a517-412e-8f3c-97c588a4b2f1]     1: <% content_for :css do %>
[66518e09-a517-412e-8f3c-97c588a4b2f1]     2:   <%= stylesheet_link_tag 'homes' %>
[66518e09-a517-412e-8f3c-97c588a4b2f1]     3: <% end %>
[66518e09-a517-412e-8f3c-97c588a4b2f1]     4:   <%= render 'shared/flash_messages'%>
[66518e09-a517-412e-8f3c-97c588a4b2f1]     5: 
F, [2020-10-12T13:28:37.845450 #22722] FATAL -- : [66518e09-a517-412e-8f3c-97c588a4b2f1]   
F, [2020-10-12T13:28:37.845472 #22722] FATAL -- : [66518e09-a517-412e-8f3c-97c588a4b2f1] app/views/homes/index.html.erb:2:in `block in _app_views_homes_index_html_erb__1348361279455874858_75120'
[66518e09-a517-412e-8f3c-97c588a4b2f1] app/views/homes/index.html.erb:1:in `_app_views_homes_index_html_erb__1348361279455874858_75120'
I, [2020-10-12T13:38:07.919149 #22721]  INFO -- : [385da9dc-780c-4a4b-93ea-77683c0f5809] Started GET "/" for 126.11.108.222 at 2020-10-12 13:38:07 +0000
I, [2020-10-12T13:38:07.919848 #22721]  INFO -- : [385da9dc-780c-4a4b-93ea-77683c0f5809] Processing by HomesController#index as HTML
D, [2020-10-12T13:38:07.956165 #22721] DEBUG -- : [385da9dc-780c-4a4b-93ea-77683c0f5809]    (2.8ms)  SET NAMES utf8mb4 COLLATE utf8mb4_general_ci,  @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'),  @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483
D, [2020-10-12T13:38:07.962259 #22721] DEBUG -- : [385da9dc-780c-4a4b-93ea-77683c0f5809]   Pcrpositive Load (3.0ms)  SELECT  `pcrpositives`.* FROM `pcrpositives` ORDER BY `pcrpositives`.`id` DESC LIMIT 1
D, [2020-10-12T13:38:07.965472 #22721] DEBUG -- : [385da9dc-780c-4a4b-93ea-77683c0f5809]   Pcrtested Load (2.8ms)  SELECT  `pcrtesteds`.* FROM `pcrtesteds` ORDER BY `pcrtesteds`.`id` DESC LIMIT 1
D, [2020-10-12T13:38:07.968633 #22721] DEBUG -- : [385da9dc-780c-4a4b-93ea-77683c0f5809]   Recovery Load (2.8ms)  SELECT  `recoveries`.* FROM `recoveries` ORDER BY `recoveries`.`id` DESC LIMIT 1
I, [2020-10-12T13:38:07.969160 #22721]  INFO -- : [385da9dc-780c-4a4b-93ea-77683c0f5809]   Rendering homes/index.html.erb within layouts/application
I, [2020-10-12T13:38:07.969980 #22721]  INFO -- : [385da9dc-780c-4a4b-93ea-77683c0f5809]   Rendered homes/index.html.erb within layouts/application (0.8ms)
I, [2020-10-12T13:38:07.970113 #22721]  INFO -- : [385da9dc-780c-4a4b-93ea-77683c0f5809] Completed 500 Internal Server Error in 50ms (ActiveRecord: 11.4ms)
F, [2020-10-12T13:38:07.970845 #22721] FATAL -- : [385da9dc-780c-4a4b-93ea-77683c0f5809]   
F, [2020-10-12T13:38:07.970881 #22721] FATAL -- : [385da9dc-780c-4a4b-93ea-77683c0f5809] ActionView::Template::Error (The asset "homes.css" is not present in the asset pipeline.
):
F, [2020-10-12T13:38:07.971160 #22721] FATAL -- : [385da9dc-780c-4a4b-93ea-77683c0f5809]     1: <% content_for :css do %>
[385da9dc-780c-4a4b-93ea-77683c0f5809]     2:   <%= stylesheet_link_tag 'homes' %>
[385da9dc-780c-4a4b-93ea-77683c0f5809]     3: <% end %>
[385da9dc-780c-4a4b-93ea-77683c0f5809]     4:   <%= render 'shared/flash_messages'%>
[385da9dc-780c-4a4b-93ea-77683c0f5809]     5: 
F, [2020-10-12T13:38:07.971197 #22721] FATAL -- : [385da9dc-780c-4a4b-93ea-77683c0f5809]   
F, [2020-10-12T13:38:07.971221 #22721] FATAL -- : [385da9dc-780c-4a4b-93ea-77683c0f5809] app/views/homes/index.html.erb:2:in `block in _app_views_homes_index_html_erb__1348361279455874858_75120'
[385da9dc-780c-4a4b-93ea-77683c0f5809] app/views/homes/index.html.erb:1:in `_app_views_homes_index_html_erb__1348361279455874858_75120'
[daiki@ip-10-0-0-56 log]$ 

なんかasset piipelineで落ちている??
と思いもう一度、Railsアプリをプリコンパイルしてみる。

EC2.
[daiki@ip-10-0-0-56 SONAERU_APP]$ bundle exec rake assets:precompile RAILS_ENV=production
Error: ENOTDIR: not a directory, open '/home/daiki/.config/yarn'
    at Error (native)
    at Object.fs.openSync (fs.js:642:18)
    at fs.readFileSync (fs.js:510:33)
    at /usr/lib/node_modules/yarn/lib/cli.js:100892:58
    at Array.map (native)
    at parseRcPaths (/usr/lib/node_modules/yarn/lib/cli.js:100890:78)
    at Object.findRc (/usr/lib/node_modules/yarn/lib/cli.js:100904:10)
    at getRcConfigForCwd (/usr/lib/node_modules/yarn/lib/cli.js:56916:74)
    at /usr/lib/node_modules/yarn/lib/cli.js:92255:56
    at next (native)
rake aborted!
Autoprefixer doesn't support Node v6.17.1. Update it.
/home/daiki/.rbenv/versions/2.7.0/bin/bundle:23:in `load'
/home/daiki/.rbenv/versions/2.7.0/bin/bundle:23:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

ん〜下から5行目あたりでnode.jsが古いと怒られていますね。
ということでnode.jsを最新版にしてみましょう!

以下の記事を参考にしました!

↓yumでのnodejsのバージョンアップにはまった話と解決方法
https://qiita.com/robitan/items/a684a81214767c21a560

#手順
まずは下記のコードを実行してroot状態にしておく

EC2.
 $  sudo su -

現在のnode.jsのバージョンを確認

EC2.
 $  node -v
    v6.12.3

node.jsのrpmを確認。2レコード出てきたら古いほうが優先されるのが原因みたいです。

EC2.
 $  ll /etc/yum.repos.d/ | grep node
    -rw-r--r--. 1 root root 472 Oct 21  2016 nodesource-el6.repo
    -rw-r--r--. 1 root root 472 Apr 26  2016 nodesource-el.repo

よって、古いほうのrpmを削除してします。

EC2.
$   rm /etc/yum.repos.d/nodesource-el.repo

一旦、yumをクリーンするコマンドを実行

EC2.
$   yum clean all

再びインストールしなおします。

EC2.
$   yum -y install nodejs

バージョンを確認

EC2.
$  $ node -v
   v12.19.0

以上

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?