简体   繁体   English

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

[英]npm install fails (unable to resolve dependency tree)

Trying to reduce any changing variables and using a fresh pull of my code.试图减少任何变化的变量并使用我的代码的新拉动。 They are no node-module packages or package-lock.json .它们不是node-module包或package-lock.json I run npm install I get this error:我运行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

If I do an install via --force or npm install --legacy-peer-deps I get a bunch of files mark as outdated and when I run npm update I get the same error.如果我通过--forcenpm install --legacy-peer-deps我会得到一堆文件标记为过时,当我运行npm update时,我会得到同样的错误。 I have tried clearning the cache of my npm as well with no luck npm cache clean .我也尝试清除 npm 的缓存,但没有运气npm cache clean I don't know why this is happening as there is no node-module folder or anything installed for it to give error under my node_modules/react-native-screens ...they are no node_modules folder yet.我不知道为什么会发生这种情况,因为在我的node_modules/react-native-screens下没有节点模块文件夹或任何安装的东西会给出错误...它们还没有 node_modules 文件夹。 What is causing this and how can I fix it?是什么原因造成的,我该如何解决?

Edit: I ran npm update -g , then npm audit fix and then I got an error:编辑:我运行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

so I ran expo install react-native-screens and saw that it couldn't find expo...checked my folder and my node_module folder is missing.所以我跑了expo install react-native-screens并看到它找不到 expo ...检查了我的文件夹并且我的node_module文件夹丢失了。 Like if it never was there or gotten installed.就像它从未存在或安装过一样。

edit: I have tried all the methods listed below and it gives random errors that I can not fix it undefined is not an object (evaluating '_core.ThemeColors.light') and I have googled this and one of the main solutions is delete npm and package-lock.json and reinstall but that brings me back to where I started.编辑:我已经尝试了下面列出的所有方法,它给出了我无法修复的随机错误undefined is not an object (evaluating '_core.ThemeColors.light') ,我已经用谷歌搜索了这个,主要解决方案之一是删除 npm和 package-lock.json 并重新安装,但这让我回到了开始的地方。

It works for me:这个对我有用:

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

Try to copy your src folder and package.json file and initialize another react-native (new) and replace the source the src folder and package.json file and reenter npm install. Try to copy your src folder and package.json file and initialize another react-native (new) and replace the source the src folder and package.json file and reenter npm install.

You can use --force in the command line, but you will problably have to deal with a broken react-native dependency later.您可以在命令行中使用 --force,但稍后您可能必须处理损坏的 react-native 依赖项。 Anyway, there are other ways of dealing with this broken dependency.无论如何,还有其他方法可以处理这种损坏的依赖关系。

Try this:尝试这个:

npm config set legacy-peer-deps true npm 配置设置 legacy-peer-deps true

Note: this will set this flag permanently注意:这将永久设置此标志

For one time:一次:

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

Try it in the following:在以下情况下尝试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM