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?

Docker + Windows(WSL2) + Vite で EACCES: permission denied (node_modules/.vite) が出たときの解決方法

0
Posted at

【結論】

Docker Desktop(WSL2)+Windows 環境で Vite を使っている場合、
node_modulesbind mount(ホスト共有)していると、Vite の依存最適化時に

EACCES: permission denied, rename node_modules/.vite/...

が発生することがあります。

解決策は node_modules を bind mount せず、named volume に切り離すことです。


【発生したエラー】

org-frontend-1  | 2:50:10 PM [vite] (client) ✨ optimized dependencies changed. reloading
org-frontend-1  | 2:52:01 PM [vite] (client) error while updating dependencies:
org-frontend-1  | Error: EACCES: permission denied, rename
org-frontend-1  | '/app/app/node_modules/.vite/deps_temp_02c88b71'
org-frontend-1  | -> '/app/app/node_modules/.vite/deps'
org-frontend-1  |     at Object.renameSync (node:fs:1018:11)

【環境】

  • Windows 11
  • Docker Desktop(WSL2 backend)
  • Vite(React)

【原因】

Vite は起動時や依存関係変更時に Dependency Pre-Bundling(依存関係の事前バンドル) を行い、
その結果をデフォルトで以下のディレクトリにキャッシュします。

node_modules/.vite

この処理では一時ディレクトリを作成したあと、

deps_temp_xxxx → deps

という rename 操作が行われます。

Windows + Docker(WSL2) 環境で node_modules を bind mount していると、
この rename が失敗することがあります。


【解決方法】

node_modules を named volume にする

node_modules をホストと共有せず、Docker 管理の volume に切り離します。

docker-compose.yml の例

services:
  org-frontend:
    volumes:
      - ./frontend:/app
      - node_modules:/app/node_modules

volumes:
  node_modules:

【補足:キャッシュが壊れている場合】

すでに .vite キャッシュが壊れている場合は、一度削除して再生成します。

rm -rf node_modules/.vite
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?