2023-07-11

npm で依存関係のエラー

❯ npm i                   
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: use-media@1.4.0
npm ERR! Found: react@17.0.2
npm ERR! node_modules/react
npm ERR!   react@"^17.0.2" from the root project
npm ERR!   peer react@">=16.8 || ^17.0.0 || ^18.0.0" from framer-motion@6.3.3
npm ERR!   node_modules/framer-motion
npm ERR!     framer-motion@"^6.3.3" from the root project
npm ERR!   11 more (iconoir-react, next, next-themes, react-burger-menu, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.1" from use-media@1.4.0
npm ERR! node_modules/use-media
npm ERR!   use-media@"^1.4.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: react@16.14.0
npm ERR! node_modules/react
npm ERR!   peer react@"^16.8.1" from use-media@1.4.0
npm ERR!   node_modules/use-media
npm ERR!     use-media@"^1.4.0" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! 
npm ERR! For a full report see:
npm ERR! /Users/amanokokorotarou/.npm/_logs/2023-07-11T14_04_52_361Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in: /Users/amanokokorotarou/.npm/_logs/2023-07-11T14_04_52_361Z-debug-0.log

use-mediaの依存しているReactのバージョンが低いらしい。

use-mediaは4年も更新されていない。use-mediaじゃないライブラリを使えないか模索。

ピンポイントの記事を発見。

【React】「streamich/use-media」の代替で「streamich/react-use」のuseMediaを使う