Fixing `Could not resolve dependency: npm ERR! peerOptional typescript@"^3.2.1" from react-scripts@4.0.1`
I tried running npm i
on a fresh git clone, and ran into this error.
% npm i
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: typescript@4.1.3
npm ERR! node_modules/typescript
npm ERR! dev typescript@"^4.1.3" from the root project
npm ERR! peer typescript@">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" from tsutils@3.18.0
npm ERR! node_modules/tsutils
npm ERR! tsutils@"^3.17.1" from @typescript-eslint/typescript-estree@4.11.1
npm ERR! node_modules/@typescript-eslint/typescript-estree
npm ERR! @typescript-eslint/typescript-estree@"4.11.1" from @typescript-eslint/parser@4.11.1
npm ERR! node_modules/@typescript-eslint/parser
npm ERR! dev @typescript-eslint/parser@"^4.11.0" from the root project
npm ERR! 3 more (react-scripts, @typescript-eslint/eslint-plugin, eslint-config-react-app)
npm ERR! 1 more (@typescript-eslint/experimental-utils)
npm ERR! tsutils@"^3.17.1" from @typescript-eslint/eslint-plugin@4.11.1
npm ERR! node_modules/@typescript-eslint/eslint-plugin
npm ERR! @typescript-eslint/eslint-plugin@"^4.5.0" from react-scripts@4.0.1
npm ERR! node_modules/react-scripts
npm ERR! react-scripts@"4.0.1" from the root project
npm ERR! 1 more (eslint-config-react-app)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional typescript@"^3.2.1" from react-scripts@4.0.1
npm ERR! node_modules/react-scripts
npm ERR! react-scripts@"4.0.1" 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.
It turns out react-scripts should but doesn't depend on typescript 4. The fix (see ticket) was merged end of Nov 2020, but as of Jan 2021, it seems that it hasn't been released yet.
So for now, running npm install --legacy-peer-deps
does the trick, as one poster says.