MeWrite Docs

npm WARN peer dep missing

npmで必要なピア依存関係がインストールされていない場合に発生

概要

npmでパッケージが必要とするピア依存関係(peer dependency)がインストールされていない場合に警告が発生します。

エラーメッセージ

npm WARN react-dom@18.2.0 requires a peer of react@^18.2.0 but none is installed.
npm WARN eslint-config-prettier@8.5.0 requires a peer of eslint@>=7.0.0 but none is installed.

原因

  1. ピア依存関係の未インストール: 必要なパッケージがない
  2. バージョンの不一致: インストール済みだがバージョンが合わない
  3. npm 7以降のstrict mode: ピア依存関係がより厳密に

解決策

1. 必要なピア依存関係をインストール

1
2
# 警告に表示されたパッケージをインストール
npm install react@^18.2.0 react-dom@^18.2.0

2. package.jsonを確認して一括インストール

1
2
3
4
5
6
{
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  }
}
1
npm install

3. –legacy-peer-depsオプション(一時的対処)

1
npm install --legacy-peer-deps

4. –forceオプション(非推奨)

1
npm install --force

5. npmrcで設定

1
2
# .npmrc
legacy-peer-deps=true

6. パッケージのバージョンを合わせる

1
2
3
4
5
# 現在のバージョンを確認
npm ls react

# 互換性のあるバージョンに更新
npm install package-name@version

7. npm outdatedで確認

1
2
3
4
5
# 古いパッケージを確認
npm outdated

# アップデート
npm update

Node.js の他のエラー

最終更新: 2025-12-09