下一个身份验证与 React 18 冲突

问题描述 投票:0回答:5

我在使用 React 18 安装 next-auth 时遇到此错误

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

是否有任何解决方案可以在不使用 --force 标志的情况下修复它?

node.js reactjs npm npm-install next-auth
5个回答
0
投票

看起来你必须降级react才能安装next auth,我已经尝试过了,我将react降级到版本17.0.2,现在可以安装next auth。如何降级反应如下

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]

我希望安装下一个身份验证时的错误已得到解决


0
投票

这是我解决这个问题的方法:

首先,发生了什么:next-auth 正在寻找react@“^16.13.1 || ^17”,但没有找到它。相反,它找到了 [email protected],这是一个较新的版本。由于某种原因不喜欢这个新版本,并且您会收到通知(这不是什么大问题,但他们认为值得停止您的构建)。

一个解决方案:强制安装next-auth想要的特定版本的react:

npm install [电子邮件受保护] 这样做的作用是将你的 React 版本回滚到与 next-auth 兼容的稍旧的版本。您不会注意到任何差异,并且在未来的迭代中,希望 next-auth 得到更新,这样这个问题就会消失。

另一个解决方案:做出全面决定,不安装任何旧版本依赖项:

npm install xxxx --legacy-peer-deps 其作用是忽略此包的旧依赖项。它更全面,可以为您做出很多决定。


0
投票

开发人员已修复此问题。再次尝试“npm install --save next-auth”,现在一切都应该可以工作了。


0
投票

错误似乎永远不会消失:)

当我遇到类似的错误时,我正在尝试安装 React google 登录依赖项。这意味着版本 的软件包有冲突。他们期望版本相同,但这实际上是不可能的。

要修复此错误,只需运行:

npm install xxxx --legacy-peer-deps

其中

xxx
是你的论点:)


0
投票

可以使用旧版本或较新版本。就我而言,我打开了 next-auth - npm 并看到了可用版本的列表。我安装了一个测试版,它解决了我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.