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

これは困った! node_modulesの暴走!

Posted at

あらまし

息抜きに、Next.jsでポートフォリオ(転職する気はないけど)を作っていた深夜1時。
ようやくいい感じになってきたなとシャワーを浴びる。
風呂上がりに開発サーバーを立ち上げると...。

Error: Cannot find module 'styled-jsx/package.json'

これは、もう一度 npm install しないといけないやつだと悟る...。
すでに 25:30...。このまま寝るか...。でも気になる。

意気揚々と、node_modulesを rm -rf する。
いつまで経っても削除が終わらない...。
ディレクトリを確認してみると...。

こんなのがいっぱい!!!

drwx------  65535 hoge  staff  2097120 Feb 13 00:40 @eslint-community 2

事象

node_modules に、"2" の文字列が付く容量のおおきいディレクトリがたくさん生成される。

結論

rm -rf を回して寝よう!

sudo rm -rf node_modules

起きたらこれで、解決です。

rm -rf package-lock.json
npm install

考えられる要因

多分開発サーバを実行しながら、ブランチの切り替えやマージなどしすぎたことが要因かと推察。
実際の要因は掴めていない。

対応

以下手順で実施。

  1. node_modulesの 削除
  2. package-lock.json 削除
  3. npm install

作業の流れ

1 の作業を行うにあたって、以下の方法を試したが、いずれも短時間では完了しなかった

a. findコマンドを使った方法

find node_modules -name "* 2" -exec rm -rf {} +

b. rsyncを使った方法

rsync -a --delete empty_dir/ node_modules/

c. incode番号を指定して削除

ls -li node_modules | grep " 2" | awk '{print $1}' | xargs -I {} find node_modules -inum {} -exec rm -rf {} +

結局うまく行ったのは、一晩中 rm -rf を回し続けること

sudo rm -rf node_modules

そのあとは、これで元通りでした。

rm -rf package-lock.json
npm install

最後に

ここまでご覧いただきありがとうございます。
要因が気になるし、かなり付け焼き刃な解決方法な気がしますので、もし何かお気づきの方は、教えてください!
それでは、いい夢を!

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