Unable to resolve dependency tree error when installing npm ...

文章推薦指數: 80 %
投票人數:10人

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@ – ValdemarVreeman May20,2021at8:09 Addacomment  |  45 Thishappensforsomepackagesafterupdatingtonpm7. Paramter--legacy-peer-depscanhelp: npmi--legacy-peer-deps Describedherelegacy-peer-deps CausesnpmtocompletelyignorepeerDependencieswhenbuildinga packagetree,asinnpmversions3through6. Ifapackagecannotbeinstalledbecauseofoverlystrict peerDependenciesthatcollide,itprovidesawaytomoveforward resolvingthesituation. ... Youcansetthisoptiontotruebydefault(notrecommendedbynpm): npmconfigsetlegacy-peer-depstrue Orjustwaituntilthesepackagesgetuptodate. Share Follow editedFeb8,2021at11:03 answeredFeb8,2021at10:14 ztomztom 8,20666goldbadges2727silverbadges4646bronzebadges Addacomment  |  37 Justdotwosimplesteps: First,executethisinyourterminal. npmconfigsetlegacy-peer-depstrue Second,clearthecache: npmcacheclean--force Andfinally,executeyourcommand.Thiswillworkforsure. Share Follow editedAug15at21:55 PeterMortensen 30.5k2121goldbadges102102silverbadges124124bronzebadges answeredApr7at17:23 VinitDabhiVinitDabhi 53155silverbadges55bronzebadges 2 3 Doesclearingcachehelphere?DowereallyneedStep2? – HariReddy Apr29at4:01 2 Pleaseaddexplanation. – justdvl Aug16at20:45 Addacomment  |  16 Theproblemisrelatedtoadependencyconflictorbrokendependency.Youcanproceedbyacceptingtheincorrectionofdependencybyforcinganinstall. Solution:Usingcommandwith--force. Yourcommandwillbelikenpminstall--force@your-npm-package. Note:Youcanuseyarntoinstalladependencyifit'savailableintoinstallwiththeyarnpackagemanager. Share Follow editedSep5,2021at22:41 PeterMortensen 30.5k2121goldbadges102102silverbadges124124bronzebadges answeredAug4,2021at17:19 AlyAly 3,48822goldbadges1111silverbadges2020bronzebadges Addacomment  |  13 NPMcanbeusedtoinstallandmanageversionsofdependenciesinyourprojects. IhaditthesameissueonReactversionsinrelationwiththenpmversion: npmerrorfoundtypes/[email protected] Soitmightbepackage-versionsthatneedtobeinstalledbasedonyourpackage.jsonfile. Itgiveserrorsinthenpm7versionandcannotinstallNode.jsmodules. Ifyouwilldowngradenpmversionto6,thoseproblemswillbecomewarningsandtheproblemwillberesolved. Trytoprovethiscommand:npminstall-gnpm@6 Checkifversionisalreadyinstalled:npm--version Removeandinstallnode_modulespackage: a)Removerm-rfnode_modules b)Install:npmi Share Follow editedAug15at22:20 PeterMortensen 30.5k2121goldbadges102102silverbadges124124bronzebadges answeredNov3,2021at9:39 RigersLekaRigersLeka 32133silverbadges55bronzebadges Addacomment  |  11 Tryremovingthenodemodulesandpackage-lock.jsonfileandruncommandnpminstall or Trynpmcacheclean--force Share Follow answeredNov5,2020at17:53 KavindaSenarathneKavindaSenarathne 1,5631111silverbadges1414bronzebadges Addacomment  |  10 FirstItried npminstall Itgavemeerrorunabletoresolvedependencytreeandbasedonthehelpinformationfromthiscommand, Fixtheupstreamdependencyconflict,orretry npmERR!thiscommandwith--force,or--legacy-peer-deps npmERR!toacceptanincorrect(andpotentiallybroken)dependencyresolution. Itriedthiscommand: npminstall--legacy-peer-deps Anditsolvedmyproblem. Share Follow editedSep5,2021at22:34 PeterMortensen 30.5k2121goldbadges102102silverbadges124124bronzebadges answeredMay20,2021at1:07 QinChenfengQinChenfeng 37155silverbadges55bronzebadges Addacomment  |  8 Thefastestsolution:npminstall--legacy-peer-deps Explanation: Innpmversions3through6,peerDependencieswerenotautomaticallyinstalled,andwouldraiseawarningifaninvalidversionofthepeerdependencywasfoundinthetree.Asofnpmv7,peerDependenciesareinstalledbydefault. npmdocs:peerDependencies YourdependencycontainssomepeerDependenciesthatconflictwiththerootproject'sdependency. AsitdescribedinthenpmERRlog. Share Follow editedSep5,2021at22:30 PeterMortensen 30.5k2121goldbadges102102silverbadges124124bronzebadges answeredApr12,2021at11:22 LitileXueZhaLitileXueZha 28944silverbadges55bronzebadges Addacomment  |  7 Trytwooptionstoresolvethisissue: Option1:Deletefoldernode_modulesfolderandfilepackage_lock.jsonafterrunning: npmcacheclean--forceafternpmi--force Option2:runnpminstall--save--legacy-peer-deps Share Follow editedAug15at22:18 PeterMortensen 30.5k2121goldbadges102102silverbadges124124bronzebadges answeredNov26,2021at9:04 aakashsharmaaakashsharma 10911silverbadge22bronzebadges Addacomment  |  5 Theproblemseemstobethatgf-kautomata-pipeline-uiisusingAngular9,while@angular/httprequiresAngular7.(@angular/httpwasdeprecatedandeventuallyremoved,andallitsfunctionalitywasmovedinto@angular/commoninstead.) See:https://www.npmjs.com/package/@angular/http Ifyou'rerunningAngular9,then delete@angular/httpfromyourpackage.json(Youdon'tneeditinAngular9) Makesureyouhave@angular/commoninyourpackage.json. Runnpmi. Ifyou'rerunningAngular7,thenopenupyourpackage.jsonandchecktomakesureallofyourAngularpackagesarenohigherthan^7.0.0.Youmayalsoneedremovegf-kautomata-pipeline-ui,orcontacttheauthorofgf-kautomata-pipeline-uiandfindoutifthelibraryiscompatiblewithAngular7. Share Follow editedNov6,2020at11:25 answeredNov5,2020at7:58 EliezerBerlinEliezerBerlin 2,53411goldbadge1212silverbadges2323bronzebadges 2 @PearlIseeinthecommentsyouwrotethatyour@angular/coreisAngular9,notAngular7.Areyouhalf-waythroughanupgradefrom7to9? – EliezerBerlin Nov5,2020at11:56 1 Thisisdefinitelythemostaccurateanswer – CrsCaballero Jul8at18:17 Addacomment  |  5 Thisworksforme: npminstall--save--legacy-peer-deps Share Follow editedAug15at21:55 PeterMortensen 30.5k2121goldbadges102102silverbadges124124bronzebadges answeredFeb21at21:11 MuhammadFahadAdoMuhammadFahadAdo 9511silverbadge22bronzebadges 0 Addacomment  |  3 Inmycase,Istartedgettingtheerror(below)afterupgradingnpmfromversion6to7. npmERR!codeERESOLVEnpmERR!ERESOLVEunabletoresolvedependency tree ... npmERR!Fixtheupstreamdependencyconflict,orretrythiscommandwith--force,or--legacy-peer-depstoacceptanincorrect(andpotentiallybroken)dependencyresolution. Inmycasecompilingwitheither--legacy-peer-depsor--forceflagsresultedinauselessbundle. SoItrieddeletingthenode_modules,package-lock.json,andbundleusingyarninstall.Thisgeneratedayarn.lockfileandcreatedpackage-lock.jsonthatworkedfineinsubsequentnpmruns. P.S.:Iamusingthetemporaryworkarounduntilnpm7worksfinewithmyproject:afterthat,Iwilldeleteyarn.lock,package-lock.jsonandfoldernode_modules,andrecompilewithnpm rm-rfnode_modules rmpackage-lock.json yarninstall #Generatesayarn.lockfileandanewpackage-lock.json #Continuewithnpm npmstart Share Follow editedSep5,2021at22:28 PeterMortensen 30.5k2121goldbadges102102silverbadges124124bronzebadges answeredApr12,2021at0:53 user9869932user9869932 5,93333goldbadges5353silverbadges4646bronzebadges 0 Addacomment  |  2 IjustupdatemyNode.jsanditworksforme: node-v Output: Vxxxx And: sudonpminstall-gn (Usethiscommandtoinstallthestablenoderelease.) sudonstable Share Follow editedSep5,2021at22:25 PeterMortensen 30.5k2121goldbadges102102silverbadges124124bronzebadges answeredApr5,2021at16:03 FarbodAprinFarbodAprin 80211goldbadge88silverbadges1616bronzebadges Addacomment  |  2 Ifyouhavenode_modulesfolderandpackage-lock.jsonfileinyourrootdirectorythenremovethose: rm-rnode_modules rmpackage-lock.json Thenruncommands: npminstall--save--legacy-peer-deps npmauditfix--force Create.envfileintherootdirectoryandpastebelowcode: SKIP_PREFLIGHT_CHECK=true Now,startyourproject: npmstart Share Follow editedSep5,2021at22:29 PeterMortensen 30.5k2121goldbadges102102silverbadges124124bronzebadges answeredApr12,2021at6:28 PrithuShahiPrithuShahi 3144bronzebadges Addacomment  |  2 Use npminstall--legacy-peer-deps Thisworkedforme. Share Follow editedAug15at21:47 PeterMortensen 30.5k2121goldbadges102102silverbadges124124bronzebadges answeredApr18at15:48 komaldubeykomaldubey 4933bronzebadges Addacomment  |  1 Ihavefacedthisissuemanytimes.AtlastIfoundasolution: npminstallreact-native-paper--legacy-peer-deps Share Follow editedSep5,2021at22:39 PeterMortensen 30.5k2121goldbadges102102silverbadges124124bronzebadges answeredJun21,2021at15:20 MazharkMazhark 15111silverbadge77bronzebadges Addacomment  |  1 Forthiscase,Iwashavingtheissue ERESOLVEunabletoresolvedependencytree inanAngular13projectthatusedsomepackagesfromaprivatenpmfeedinAzureDevOps. Toaccessthisrepository,Icreatedan.npmrcfile.Becauseofthis,thenpminstallcommandwouldsearchallpackagesinmyprivaterepositoryandnotinnpmfeedanymore.Theunabletoresolvethedependencytreeerrorhappenedbecausethenpminstallcommandcouldnotfindmanyofthepackagesthatwerehostedinthenpmfeedandnotmyprivatefeed. Ifoundthisamazingansweronhowtoscopepackages. Basedonthis,Imadesomechanges: InmylibraryPackage.json,updatethenametohaveascopename@mylib "name":"@myLib/command-queue", Buildandpublishthispackagetomyprivatefeed Inmyclientapp(theonethatusesthispackage),updatethe.npmrcfiletousemyprivatefeedforpackagesinthisscopeonly @myLib:registry=https://pkgs.dev.azure.com/... always-auth=true Now,wheneverIrunthecommandnpminstall,ifthepackagehasthescope@myLib,itwilllookforitinmyprivatefeed,andusethenpmfeedforallothercases(i.e.,@angular/...) ThisisanexampleofmyclientappPackage.jsonfile: "@angular/platform-browser-dynamic":"~13.3.0", "@angular/router":"~13.3.0",



請為這篇文章評分?