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?

pnpm addでERR_PNPM_ADDING_TO_ROOTという警告が出るのを解消する

0
Posted at

やろうとしたこと

pnpmで動いているアプリにライブラリをインストールしようとした。

警告の内容

$ pnpm add --save-dev jest
 ERR_PNPM_ADDING_TO_ROOT  Running this command will add the dependency to the workspace root, which might not be what you want - if you really meant it, make it explicit by running this command again with the -w flag (or --workspace-root). If you don't want to see this warning anymore, you may set the ignore-workspace-root-check setting to true.

DeepL翻訳

このコマンドを実行すると、依存関係がワークスペースルートに追加されます。これは意図しない動作かもしれません。本当にワークスペースルートに追加したい場合は、-w フラグ(または --workspace-root)を指定して再度このコマンドを実行し、明示的に指定してください。この警告を今後表示したくない場合は、`ignore-workspace-root-check` 設定を true に設定できます。

pnpm addを実行したディレクトリはアプリケーション配下なのに、ワークスペースルートにインストールしようとしています。
本当にワークスペースルートにインストールしたい場合は-wをつければ実行できますが、今回はアプリケーション内だけで依存を管理したいので-wはつけたくありません。

解決

プロジェクト配下にpnpm-workspace.yamlというファイルがありました。
このファイルがあると、複数のpackage.jsonを管理する前提になり警告が表示されるようです。

任意の依存の上書きをしたい場合などは本ファイルに記述していくのですが、今回は必要ないのでファイルを削除します。
公式サイト

$ pnpm add --save-dev jest
 WARN  2 deprecated subdependencies found: glob@7.2.3, inflight@1.0.6
Packages: +199
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Progress: resolved 632, reused 370, downloaded 199, added 199, done

devDependencies:
+ jest 30.2.0

Done in 1.8s

先程の警告がなくなりました。

最後に

小さな発見ですが誰かの役に立つと嬉しいです。
見ていただきありがとうございました。

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?