i get this error when installing next-auth with react 18
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR! react@"18.1.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.13.1 || ^17" from [email protected]
npm ERR! node_modules/next-auth
npm ERR! next-auth@"*" 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! See C:\Users\mizzo\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\mizzo\AppData\Local\npm-cache\_logs\2022-04-27T14_07_48_165Z-debug-0.log
is theres any solution to fix it without using --force flag ?
CodePudding user response:
looks like you have to downgrade react to be able to install next auth, I've tried it, I downgraded react to version 17.0.2 and now can install next auth. How to downgrade react as follows
remove new version
npm uninstall next react react-dom @types/react @types/react-dom
install old version
npm install [email protected] [email protected] [email protected]
npm install -D @types/[email protected] @types/[email protected]
I hope the error installing next auth has been resolved
CodePudding user response:
Here's how I solved this problem:
First, what's happening: next-auth is looking for react@"^16.13.1 || ^17", but it is not finding it. Instead it is finding [email protected], which is a newer version. For some reason doesn't like this newer version, and you are being notified (it is not a big deal, but they decided it was worth stopping your build).
One solution: forcibly install the specific version of react that next-auth wants:
npm install [email protected] What this does is roll back your react version to a slightly older one that is compatible with next-auth. You won't notice any difference, and in future iterations, hopefully next-auth is updated, so this goes away.
Another solution: make a sweeping decision to not install any older version dependencies:
npm install xxxx --legacy-peer-deps What this does is ignore old dependencies for this package. It is more comprehensive, and makes a lot of the decisions for you.