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?

エラー対処:Cannot read file "../package.json": permission denied (Claude Code)

0
Last updated at Posted at 2026-06-17

Sandbox機能を有効にしたClaude CodeでVitestを実行すると、親ディレクトリのpackage.jsonを読み込めずエラーになることがある。
これの対処法を記載する。

ちなみに、今回の根本的原因は恐らくVitestではなくesbuildの方。

エラー詳細

claude codeで、サブディレクトリをcdにしてからVitestを実行するとエラになることがある。

コマンド例

! cd ./foo/bar; pnpm test

エラー内容冒頭

 $ vitest --config vitest.config.ts --root . --run
 ✘ [ERROR] Cannot read file "../../package.json": permission denied

 failed to load config from /home/user/foo/bar/mysystem/vitest.config.ts

 ⎯⎯⎯⎯⎯⎯⎯ Startup Error ⎯⎯⎯⎯⎯⎯⎯⎯
 Error: Build failed with 1 error:
 error: Cannot read file "../../package.json": permission denied
     at failureErrorWithLog (/home/user/foo/bar/mysystem/node_modules/.pnpm/
 esbuild@0.27.7/node_modules/esbuild/lib/main.js:1748:15)

補足:プロンプト入力欄に!から始めることで、サンドボックス環境内でのコマンド動作を検証できます。
もし何らかのファイルを手動で書き換えた場合は、一旦Claude Codeを再起動してからコマンドを実行してください。(反映されないことがある為)

対処法

  1. claudeを最初に実行したディレクトリ(≒プロジェクトルートディレクトリ)に、適当な内容のpackage.jsonを置く
  2. Sandbox設定を見直し、今置いたpackage.jsonへのアクセスを拒否していないことを確認する
    • Sandboxの権限設定はdenyよりallowの方が強いので、もし拒否していた場合はallowReadに"./package.json"を加える
package.json
{}

↑特に希望がなければこれだけの内容でOK。

原因(推測)

  • テスト実行時にvitest.config.tsの読み取り等に使われているesbuildが実行されていた
  • esbuildがプロジェクトルートのpackage.jsonを読もうとしてエラーになった
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?