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?

MCPでnpm / npx 実行時に発生する ENOTEMPTY エラーの解決方法

Posted at

npm / npx 実行時に発生する ENOTEMPTY エラーの解決方法

発生したエラー

npx 実行時に以下のようなエラーが出ることがあります。

npm error code ENOTEMPTY
npm error syscall rename
npm error path /home/USER/.npm/_npx/xxxx/node_modules/...
npm error dest /home/USER/.npm/_npx/xxxx/node_modules/.xxxx-xxxx
npm error errno -39
npm error ENOTEMPTY: directory not empty, rename ...

さらに MCP client for chrome-devtools failed to start: request timed out のように関連プロセスが起動できないケースもありました。


原因

  • npx が利用する一時ディレクトリ (~/.npm/_npx/) に壊れたキャッシュが残っており、
    ディレクトリのリネームができなくなっている。
  • その結果、パッケージの展開や実行が中途で失敗する。

解決方法

キャッシュを削除してクリーンな状態にすれば解決します。

# npx の一時キャッシュを削除
rm -rf ~/.npm/_npx

# npm キャッシュもクリア
npm cache clean --force

これで再度 npx パッケージ名 を実行すると正常に動作しました。


ポイント

  • ENOTEMPTY は「ディレクトリが空でないのでリネームできない」という意味。
  • キャッシュ破損が原因なので、キャッシュを消すのが最短解決策
  • どうしても繰り返す場合は、対象パッケージを npm install -g でグローバルに入れる方法もある。

まとめ

  • npx 実行時の ENOTEMPTY rename エラーはキャッシュ破損が原因。
  • rm -rf ~/.npm/_npx && npm cache clean --force で解決可能。
  • 再現しやすい環境ではグローバルインストールも検討するとよい。

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?