Unable to resolve dependency tree error when installing npm ...
文章推薦指數: 80 %
You have dependency conflict (incorrect and potentially broken dependency) as it says, so try to run the command with --force , or --legacy-peer ...
Home
Public
Questions
Tags
Users
Companies
Collectives
ExploreCollectives
Teams
StackOverflowforTeams
–Startcollaboratingandsharingorganizationalknowledge.
CreateafreeTeam
WhyTeams?
Teams
CreatefreeTeam
Collectives™onStackOverflow
Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost.
LearnmoreaboutCollectives
Teams
Q&Aforwork
Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch.
LearnmoreaboutTeams
Unabletoresolvedependencytreeerrorwheninstallingnpmpackages
AskQuestion
Asked
1year,11monthsago
Modified
today
Viewed
892ktimes
530
138
Whentryingtoinstallthenpmpackagesusingnpmicommand,Iamgettingthefollowingexception:
IhavetriedreinstallingtheNode.jspackageandsettingtheproxytooffusing:
setHTTP_PROXY=
setHTTPS_PROXY=
Theissueisstillthere.WhatIamdoingwrong?
Update:
WhenIrunthefollowingcommand:
npminstall--legacy-peer-deps
Thefollowingerrorisdisplayed:
angulartypescriptnpmangular9
Share
Follow
editedAug11at9:28
ShashankVivek
16k88goldbadges6060silverbadges9898bronzebadges
askedOct28,2020at12:46
PearlPearl
6,63377goldbadges3838silverbadges5656bronzebadges
12
4
Showyourpackage.json-itlookslikeyou'veupgraded@angular/core,butdidnotupgrade@angular/http?
– Adam
Oct28,2020at18:41
my@angular/coreversionis9.1.4,soshalliupdate@angular/http?
– Pearl
Oct29,2020at6:01
Pleaseshareyourpackage.jsonfile.Theproblemseemstobeinyourdependencies
– OwenKelvin
Nov1,2020at8:52
Canyoutrytodeletepackage-lock.jsonandnode_modulesandtrytorunnpmupdate?Letmeknowifitwork.
– Fmerco
Nov3,2020at10:08
1
isthisstillhappening?Canyousharethepackage.jsonfile?
– SupunPraneeth
Nov4,2020at14:15
|
Show7morecomments
28Answers
28
Sortedby:
Resettodefault
Highestscore(default)
Trending(recentvotescountmore)
Datemodified(newestfirst)
Datecreated(oldestfirst)
602
+50
ThisisnotrelatedtoanHTTPproxy.
Youhavedependencyconflict(incorrectandpotentiallybrokendependency)asitsays,sotrytorunthecommandwith--force,or--legacy-peer-deps.Ifitdoesn'ttakeeffect,thetemporarysolutionisusingpriorversionsoftheNode.js(downgradingtheNode.jsversion)asitcausesthiskindoferrorstohappensometimes.
UpdatebasedontheOP'supdate:
Asyousee,itfiresthefollowingerror:
Nomatchingversionfoundfor@angular/http@^9.1.4.
Takealookatangular/httppage.Notethatthelatestversionforthatdeprecatedpackageis7.2.16whileyourequestanupperversion(e.g.,^9.1.4)!So,trytochecktheprojectdependenciesandfollowtheraisederrorsinordertosolvetheproblem.
Share
Follow
editedSep5,2021at21:55
PeterMortensen
30.5k2121goldbadges102102silverbadges124124bronzebadges
answeredOct30,2020at20:48
AmirhosseinMehrvarziAmirhosseinMehrvarzi
16k77goldbadges4343silverbadges6969bronzebadges
11
@Pearlpleaseshowtheoutputresultof--forceand--legacy-peer-depscommands
– AmirhosseinMehrvarzi
Nov2,2020at10:31
125
Thanksnpminstall--legacy-peer-depsworksforme
– GauravPatil
Apr13,2021at5:15
willthatflaginstallonlypeerdeps?
– Aashiq
May26,2021at11:50
6
@AashiqahmedIttellsNPMtoignorepeerdepsandproceedwiththeinstallationanyway
– AmirhosseinMehrvarzi
May26,2021at12:25
3
Thanks,downgradenodeversionfrom15to14workedforme.
– asmaa
Mar8at12:41
|
Show6morecomments
271
Trythiscommand-
npminstall--save--legacy-peer-deps
Share
Follow
answeredDec17,2020at21:10
AliHasanAliHasan
2,93711goldbadge44silverbadges77bronzebadges
4
134
pleaseexplainwhatitdoes
– ESP32
Apr14,2021at13:10
18
@Gerfried,IttellsNPMtoignorepeerdepsandproceedwiththeinstallationanyway.
– Aashiq
May27,2021at7:05
1
Ifusingnpm5orgreaternoneed--saveflagasitautomaticallysavesdependencies
– Naga
Feb11at10:06
1
Ithalf-installsAngular7,andhalf-installsangular9.Ifyoudothis,itmightactuallywork,butmaygodhavemercyonyou,becauseyou'reDEFINITELYrunningsomelibrariesthatareincompatiblewithyourcurrentversionofAngular.
– EliezerBerlin
Jul17at11:46
Addacomment
|
175
Firsttounderstandtheproblem.HereiswhatIhaveaserror:
npmERR!ERESOLVEunabletoresolvedependencytree
npmERR!
npmERR!Whileresolving:[email protected]
npmERR!Found:@angular/[email protected]
npmERR!node_modules/@angular/common
npmERR!@angular/common@"11.0.3"fromtherootproject
npmERR!
npmERR!Couldnotresolvedependency:
npmERR!peer@angular/common@"^9.1.0||^10.0.0"from@agm/[email protected]
npmERR!node_modules/@agm/core
npmERR!@agm/core@"3.0.0-beta.0"fromtherootproject
Firstyoushouldstarttoreadtheproblemfromthebottomtothetop.Here@agm/core@3.0.0-beta.0requiresangularcommon9.1.0or10.0.0.Andthetopmessagesaysthattheangularcommonfoundisactually11.0.3.
(Ifyouwanttounderstanddependencieslittlebitbetter,hereisverysimplesite:Hownpm3Works)
dependencies—thesearetheessentialdependenciesthatyourelyonandcallinyourproject’scode
devDependencies—theseareyourdevelopmentdependencies,forexample,aprettierlibraryforformattingcode
peerDependencies—ifyousetapeerdependencyinyourpackage.json,youaretellingthepersonwhoinstallsyourpackagethattheyneedthatdependencywiththespecifiedversion
optionalDependencies—thesedependenciesareoptionalandfailingtoinstallthemwillnotbreaktheinstallationprocess
bundledDependencies—it’sanarrayofpackagesthatwillcomebundledwithyourpackage.Thisisusefulwhensome3rdpartylibraryisnotonNPM,oryouwanttoincludesomeofyourprojectsasmodules
Sowhatshouldbethesolutionthen?Theproblemisaboutpeerdependencies.Thesolutionistodowngradeangularcommonorthesolutionistouselegacydependencieslogicforinstallingpackagesusing--legacy-peer-deps.So--legacy-peer-depsdoesnottrytoinstallthepeerDependenciesautomatically.Isthisgoingtoworkforyou?Probably,yes.Butyoushouldaddspecificinstructionshowtodothat,ortomaketheuseof--legacy-peer-depsautomaticforfutureinstallationoftheprojectpackageswiththiscodefromoneofthepreviousanswers:
npmconfigsetlegacy-peer-depstrue
InmycaseIinstalledthepackageandItriedtorunngserve,butbecause--legacy-peer-depswasused,thereweredependencypackageswhichwerenotinstalled.Ihadtoinstallthosemanually(becauseIdidnotsettheconfigurationfromthecodeabove).Attheendinstallingaboutfivepackagesmanually,allwith--legacy-peer-deps,IendedtoapackagethatcouldnotbeinstalledandIdidnottrytocontinue,becausemyprojectwasthrowingwarningslikecrazyandtherewerealotofpackagesforaudittoo.Somydecisionwasnottousethispackageandtofindanalternative.
OthersolutionsthatIreadaboutalongtheway:
downgradeNode.jstov14.Thiswilldowngradenpm.Itmightnotbev14,butthiswastheversionthatwasmostwidelydowngradedto.
SomepeopleuseYarntoforcepackageinstallation-personallyIdon'tunderstandhowthisworks,becauseIhaven'tusedYarn.
downgradingAngularandtheglobalAngularCLIversiontoversionthatwillsatisfytherequirement.Inmycaseitisangular/common,andinthequestionit'sangular/core,butbothrequiredowngradingthewholeangularright(Iamnotsureaboutthishere).
thepackageyouinstallmighthaveahigherversionthatdoesn'trequiredowngradingAngular.Youmighttrytousethehttps://updatepackagejson.com/toupgradeyourpackagestothelatest,butthisisincaseyourprojectisquitenew.
Share
Follow
editedSep10,2021at11:16
answeredJun26,2021at4:56
makkasimakkasi
4,68933goldbadges4444silverbadges5858bronzebadges
3
5
That'sthebestanswerbecauseitistheonlyanswerwhichexplainedtheerrorlogfromOPinsteadofstupidlyapplyingforceorlegacy-peer-depsoption.Bettertosticktonpm6thanpushingnpm7andforce/legacy-peer-depsonittoavoidfixingyourdependenciesissues
– HoLengZai
Apr12at7:52
1
Byfarthebestanswer,othersjustfixtheissue,butnotcaringabouttheunderlyingproblemnorgiveinsightfulsuggestionsonwhytheissueisoccurring.
– jeffng50
May18at9:27
I'mnewtonpmbutIbelieveusingnpminstall--forceisbetter,becauseitonlyignorespeer-dependencieswhennecessary,while--legacy-peer-depsadoptsthenpmv6approachandignorespeer-dependenciescompletely.See@HongboMiao'sanswer:stackoverflow.com/questions/66020820/…
– s6mike
Jul25at1:38
Addacomment
|
114
Inadditiontousingthe--legacy-peer-depscommandlineoption,thiscanalsobesetmorepermanentlyasaconfigoption:
npmconfigsetlegacy-peer-depstrue
Share
Follow
answeredJan15,2021at9:18
friederbluemlefriederbluemle
30k1414goldbadges100100silverbadges100100bronzebadges
4
5
Thebestoptionifnpminstallisrunindirectly,e.g.byascript.
– kszl
Jun24,2021at19:57
5
whatdoesthisdo
– Sam
Aug10,2021at23:36
@Arefe,Aashiqexplainedinanother,similaranswer,thatthiscommand(legacy-peer-deps)"tellsNPMtoignorepeerdepsandproceedwiththeinstallationanyway"
– AlvaroRodriguezScelza
Nov16,2021at21:08
npmconfigsetlegacy-peer-depstrueThiscommandisworkingforme,Thanks
– KrishanGopal
Apr22at9:34
Addacomment
|
77
Finally,Ifoundtheanswer.Trythiscommand-
npminstall--save--legacy-peer-deps
Describedherelegacy-peer-deps
Share
Follow
editedMay16at8:37
answeredDec8,2021at9:18
VinaySomawatVinaySomawat
1,3371212silverbadges1919bronzebadges
2
20
Anexplanationwouldimprovethisanswer
– derekbaker783
Mar3at16:44
4
Edittheanswerwithanexplanation.
– VinaySomawat
May16at8:38
Addacomment
|
67
Whenusingnpm7,thiscomesupalotbecausepeerdependenciesissuesaretreatedaserrorsinversion7whereastheyweregenerallyonlywarningsinversion6.Usuallyusing--legacy-peer-depsmakesitworkwithnpm7.
Whenthatdoesn'twork,anoptionistodowngradetonpm6.DowngradingNode.jsisnotnecessary(butnotharmfuleither).Therelevantdependencymanagementcodeisinnpm.DowngradingNode.jswilloftenworkcoincidentallybecausedoingsowilloftendowngradenpmaswell.
Anotheroptionthatislessdisruptivethandowngradingnpmisusingnpxtousethepreviousversionofnpmforjusttheinstallcommand:npx-pnpm@6npminstall
Andwhenallelsefails,it'softenworthashottoremovethenode_modulesdirectoryandpackage-lock.json,andthenrunnpminstallagain.Thatregeneratesnode_modulesandpackage-lock.json.
Share
Follow
editedAug22,2021at17:28
answeredNov4,2020at14:06
TrottTrott
62k2222goldbadges159159silverbadges201201bronzebadges
2
Whatisthebestwaytopermanentlydowngradetonpm6?
– alentejo
Apr12,2021at8:59
2
@alentejobyremovingthenpmfolderintheC:\Users\{yourname}\AppData\Roaming,npmcacheclear--forceandthennpminstall-gnpm@
延伸文章資訊
- 1Unable to resolve dependency tree error in Angular while ...
To fix Unable to resolve dependency tree error in Angular while installing `npm` packages follow ...
- 2npm - ERR! code ERESOLVE - CSDN博客
ERESOLVE unable to resolve dependency tree. npm ERR! npm ERR! Found: [email protected]. npm ERR! nod...
- 3[Solved] ERESOLVE Unable to resolve dependency tree error ...
To Solve ERESOLVE Unable to resolve dependency tree error when installing npm packages You have d...
- 4Unable to resolve dependency tree error when ... - ItsMyCode
Solution 1: Ignore the peerDependencies ... The easiest way to fix the issue is to pass an additi...
- 5npm 安裝依賴報錯npm ERR! ERESOLVE unable to ... - 有解無憂
ERESOLVE unable to resolve dependency tree. 2021-05-03 08:06:02 區塊鏈. PS F:\devops_common\cloud-vu...