Yarn「doesn't seem to be part of the project」の原因と直し方
Yarn の doesn't seem to be part of the project は、workspaces に足せば直る。
親にある package.json や yarn.lock がプロジェクトの根と見なされている。
別のプロジェクトにするなら空の yarn.lock を置く。
公開: 更新:
yarn install … Usage Error: The nearest package directory (/tmp/tmp.N2vFQglGOr/app/packages/web) doesn't seem to be part of the project declared in /tmp/tmp.N2vFQglGOr/app. - If /tmp/tmp.N2vFQglGOr/app isn't intended to be a project, remove any yarn.lock and/or package.json file there. - If /tmp/tmp.N2vFQglGOr/app is intended to be a project, it might be that you forgot to list packages/web in its workspace configuration.
yarn install … ➤ YN0000: └ Completed ➤ YN0000: ┌ Link step ➤ YN0000: └ Completed ➤ YN0000: · Done in 0s 26ms
2026-11-09 に node:22-bookworm-slim(Yarn 4.9.2 / Node.js 22.23.4) で実際に打って取った出力。検証環境の詳細
要約
Yarn は、カレントディレクトリより上にある package.json と yarn.lock の場所をプロジェクトの根として扱う。
その根の下にあるのに workspaces に入っていないフォルダで yarn install を打つと、次のエラーで終了コード 1 になる。
Usage Error: The nearest package directory (/app/packages/web) doesn't seem to be part of the project declared in /app.Yarn 4.9.2 と 3.8.7 ではこのエラーが出て、Yarn 1.22.22 では同じ配置でもインストールが進んだ。
エラー文の下に出る 3 つの案内が、そのまま直し方になる。
どれを選ぶかは、そのフォルダをルートのワークスペースにしたいか、別のプロジェクトにしたいかで決まる。
実行例
node:22-bookworm-slim のコンテナで、workspaces の無いルートの下の packages/web から yarn install を打つと、終了コード 1 で The nearest package directory のエラーになった。
ルートに workspaces を足すか、tools/x に空の yarn.lock を置くと、同じコマンドが終了コード 0 で通った。
$ yarn install
Usage Error: The nearest package directory (/tmp/tmp.N2vFQglGOr/app/packages/web) doesn't seem to be part of the project declared in /tmp/tmp.N2vFQglGOr/app.
- If /tmp/tmp.N2vFQglGOr/app isn't intended to be a project, remove any yarn.lock and/or package.json file there.
- If /tmp/tmp.N2vFQglGOr/app is intended to be a project, it might be that you forgot to list packages/web in its workspace configuration.
- Finally, if /tmp/tmp.N2vFQglGOr/app is fine and you intend packages/web to be treated as a completely separate project (not even a workspace), create an empty yarn.lock file in it.
$ yarn install [--json] [--immutable] [--immutable-cache] [--refresh-lockfile] [--check-cache] [--check-resolutions] [--inline-builds] [--mode #0]
$ echo $?
1$ cat ../../package.json
{
"private": true,
"packageManager": "yarn@4.9.2",
"workspaces": ["packages/*"]
}$ yarn install
➤ YN0000: · Yarn 4.9.2
➤ YN0000: ┌ Resolution step
➤ YN0085: │ - root@workspace:.
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done in 0s 26ms
$ echo $?
0$ yarn install
Usage Error: The nearest package directory (/tmp/tmp.N2vFQglGOr/app/tools/x) doesn't seem to be part of the project declared in /tmp/tmp.N2vFQglGOr/app.
- If /tmp/tmp.N2vFQglGOr/app isn't intended to be a project, remove any yarn.lock and/or package.json file there.
- If /tmp/tmp.N2vFQglGOr/app is intended to be a project, it might be that you forgot to list tools/x in its workspace configuration.
- Finally, if /tmp/tmp.N2vFQglGOr/app is fine and you intend tools/x to be treated as a completely separate project (not even a workspace), create an empty yarn.lock file in it.
$ yarn install [--json] [--immutable] [--immutable-cache] [--refresh-lockfile] [--check-cache] [--check-resolutions] [--inline-builds] [--mode #0]
$ echo $?
1$ touch yarn.lock$ yarn install
➤ YN0000: · Yarn 4.9.2
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done in 0s 29ms
$ echo $?
0— 2026-11-09 時点の出力
検証環境Node.js 22.23.4 / npm 10.9.9 / Yarn 4.9.2 / 2026-11-09 検証
- 検証日
- 実行環境
node:22-bookworm-slimDebian GNU/Linux 12 (bookworm)- バージョン
- Node.js 22.23.4
- npm 10.9.9
- Yarn 4.9.2
この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。
解決策
1. ルートの workspaces に足す
ワークスペースとして扱うなら、ルートの package.json にフォルダのパターンを書く(Yarn のワークスペースの説明(新しいタブで開く))。
{
"private": true,
"packageManager": "yarn@4.9.2",
"workspaces": ["packages/*"]
}workspaces を足すと、同じ /app/packages/web での yarn install は終了コード 0 で通った。yarn.lock に新しいワークスペースが加わるので、変わった yarn.lock もコミットしておく。
2. 別のプロジェクトにするなら空の yarn.lock を置く
cd tools/x
touch yarn.lock
yarn install空の yarn.lock があると、Yarn はそのフォルダを独立したプロジェクトの根として扱う。/app/tools/x に空の yarn.lock を置くと、親の /app がプロジェクトのままでも yarn install が終了コード 0 で終わった。
3. 不要な親のファイルを消す
エラー文の declared in の後に出るパスが、Yarn が根と見なした場所である。
そこにプロジェクトを置いた覚えが無ければ、その場所の package.json と yarn.lock を消してから打ち直す。
よくある原因
- モノレポのルートにある
package.jsonのworkspacesに、そのフォルダが入っていない。/app/package.jsonにworkspacesが無い状態で/app/packages/webからyarn installを打つと、このエラーになった。 - 独立させたいフォルダの親に、別のプロジェクトの
package.jsonとyarn.lockがある。
リポジトリの中に置いたツール用のフォルダなどで起きる。 - ホームディレクトリなど上の階層に、誤って作った
package.jsonやyarn.lockが残っている。