npm安装失败(无法解决依赖树)

11

尝试减少任何可变变量,并使用最新的代码拉取。没有 node-module 包或 package-lock.json。我运行 npm install,出现以下错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: undefined@undefined
npm ERR! Found: react-native-screens@2.15.2
npm ERR! node_modules/react-native-screens
npm ERR!   react-native-screens@"~2.15.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react-native-screens@"^1.0.0 || ^1.0.0-alpha" from react-navigation-drawer@1.4.0
npm ERR! node_modules/react-navigation-drawer
npm ERR!   react-navigation-drawer@"^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! See /Users/myname/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/myname/.npm/_logs/2021-05-22T01_16_02_351Z-debug.log

如果我通过--forcenpm install --legacy-peer-deps安装,则会出现很多标记为过时的文件,当我运行npm update时,会出现相同的错误。我已经尝试清除我的 npm 缓存,但没有成功 npm cache clean。我不知道为什么会发生这种情况,因为没有 node-module 文件夹或其他任何安装在node_modules/react-native-screens下导致错误...还不存在 node_modules 文件夹。是什么原因导致了这个问题,我该如何解决?
编辑: 我运行了npm update -g,然后运行npm audit fix,然后出现了一个错误:
code ERESOLVE
ERESOLVE unable to resolve dependency tree

While resolving: Sculp latest app@undefined
Found: react-native-screens@2.15.2
node_modules/react-native-screens
react-native-screens@“~2.15.0” from the root project

我运行了expo install react-native-screens,发现找不到expo...检查了我的文件夹和node_module文件夹已经丢失,就好像它从未存在过或者没有被安装。

编辑:我尝试了下面列出的所有方法,但是会出现一些无法解决的随机错误undefined is not an object (evaluating ‘_core.ThemeColors.light’)。我已经谷歌搜索过并且其中一个主要的解决方案是删除npm和package-lock.json,然后重新安装,但这将使我回到原点。


这个回答解决了你的问题吗?安装npm包时出现无法解析依赖树错误 - Vega
5个回答

19

对我来说有效:

npm install --save --legacy-peer-deps

所有东西都安装好了,但是接着就一个错误接着一个错误,而我无法解决的最后一个错误是 undefined is not an object (evaluating ‘_core.ThemeColors.light’) - Bruce Mathers
运行得非常顺利。 - Sushant Rajbanshi

3
尝试以下操作:
npm config set legacy-peer-deps true 注意:此操作将永久设置该标志。
仅一次性操作:
npm install --save --legacy-peer-deps

0
尝试复制您的src文件夹和package.json文件,并初始化另一个React Native(new),然后替换源src文件夹和package.json文件,重新输入npm install。

你能展示一下在重新安装所有依赖项之前和之后的文件夹结构吗? - Jokanola

0

你可以在命令行中使用--force选项,但是后面你可能要处理react-native的损坏依赖问题。无论如何,还有其他方法来处理这个损坏的依赖关系。


-3

在下面尝试一下:

npm add react-native
expo install (your needed module)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接