国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

npm install報錯unable to resolve dependency tree

這篇具有很好參考價值的文章主要介紹了npm install報錯unable to resolve dependency tree。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一、問題背景

npm install安裝項目依賴時報錯

PS D:\test> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: vue-admin-template@4.2.1
npm ERR! Found: webpack@5.74.0
npm ERR! node_modules/webpack
npm ERR!   dev webpack@"^5.11.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"^3.1.0" from extract-text-webpack-plugin@3.0.2
npm ERR! node_modules/extract-text-webpack-plugin
npm ERR!   extract-text-webpack-plugin@"^3.0.2" 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 D:\Program\nodejs\node_cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     D:\Program\nodejs\node_cache\_logs\2022-08-23T01_38_42_815Z-debug.log
PS D:\test> npm install --legacy-peer-deps

解決:npm install --legacy-peer-deps

其實提示上有:npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps

二、什么是peerDependency?

  在日常使用命令npm install / npm install XX下載依賴的操作中,如果你使用的是 npm v7 以上的版本,那么應該經常會遇到無法解析依賴樹的問題(依賴沖突),就如我在上面遇到的那樣報錯

  但是每當遇到這種情況的時候,我用命令npm install --legacy-peer-deps就可以順利進行下載操作。

1、這是為什么呢?帶著好奇心,我去研究學習了一番npm install xxxx --legacy-peer-deps命令是什么?為什么可以解決下載時候產生的依賴沖突呢?

  我們日常在前端項目開發(fā)過程中,見到最多的一定是package.json文件里的devDependencies(用于在開發(fā)環(huán)境下依賴的模塊)和dependencies(無論開發(fā)環(huán)境還是生產環(huán)境都需要的依賴模塊)這兩個字段

  那么命令--legacy-peer-dep里的peerDependency是什么依賴呢?根據geeksforgeeks網站里的定義:

Peer Dependencies: In package.json file, there is an object called as peerDependencies and it consists of all the packages that are exactly required in the project or to the person who is downloading and the version numbers should also be the same. That is the reason they were named as peerDependencies. The best example is ‘react’ which is common in every project to run similarly.

  翻譯一下就是說,在package.json文件中,存在一個叫做peerDependencies(對等依賴關系)的對象,它包含了項目里需要的所有的包或者用戶正在下載的版本號相同的所有的包(很繞,但意思就是對等依賴關系指定我們的包與某個特定版本的npm包兼容);對等依賴關系最好的例子就是React,一個聲明式的創(chuàng)建用戶界面的JS庫。

2、那么我們?yōu)槭裁葱枰獙Φ纫蕾囮P系呢?

  假設我們現在有一個Hello工程,已經在其根目錄下的package.json文件中的dependencies字段里聲明了packageA作為依賴,而其下面有兩個項目app_A和app_B,它們也依賴packageA。如果我們用dependencies而不是peerDepenedencies來聲明,那么npm install安裝完項目之后的依賴結構如下圖所示:

npm install報錯unable to resolve dependency tree

 從上圖可以看出,packageA依賴包被安裝了3次,造成了2次安裝冗余。

  而如果采用peerDepenedency來下載,就可以避免這個核心依賴庫被重復下載的問題。還是上面那個場景,我們在項目app_A和app_B的package.json文件里的peerDependencies字段聲明一下核心依賴庫packageA,然后在根目錄的package.json文件里的dependencies字段也聲明一下packageA。

npm install報錯unable to resolve dependency tree

接著再執(zhí)行npm install,生成的依賴結構就會如下圖所示:

npm install報錯unable to resolve dependency tree

如上圖所示,packageA就只會被安裝一次??梢钥吹竭@時候生成的依賴圖是扁平的,packageA 也只會被安裝一次。

  因此我們總結下在插件使用dependencies聲明依賴庫的特點:

  • 如果用戶顯式依賴了核心庫,則可以忽略各插件的peerDependencies聲明;

  • 如果用戶沒有顯式依賴核心庫,則按照插件peerDependencies中聲明的版本將庫安裝到項目根目錄中;

  • 當用戶依賴的版本、各插件依賴的版本之間不相互兼容,會報錯讓用戶自行修復。

  npm 從版本v7開始,install就默認以peerDependencies的方式去下載了:

  1. 如果用戶在根目錄的package.json文件里顯式依賴了核心庫,那么各個子項目里的peerDepenedencies聲明就可以忽略

  1. 如果用戶沒有顯式依賴核心庫,那么就按照子項目的peerDepenedencies中聲明的版本將依賴安裝到項目根目錄里

  而方式2就會導致一個問題:用戶依賴的包版本與各個子項目依賴的包版本相互不兼容,那么就會報錯(無法解析依賴樹的問題(依賴沖突))讓用戶自行去修復,因而導致安裝過程的中斷。(因為是從npm v7引入的,因此npm v3-v6就不會發(fā)生這個錯誤)

3、npm install xxxx --legacy-peer-deps命令是什么?為什么可以解決下載時候產生的依賴沖突呢?

  npm install xxxx --legacy-peer-deps命令與其說是告訴npm要去干什么,不如說是告訴npm不要去干什么。

  legacy的意思:遺產/(軟件或硬件)已過時但因使用范圍廣而難以替代的;而npm install xxxx --legacy-peer-deps命令用于繞過peerDependency里依賴的自動安裝;它告訴npm忽略項目中引入的各個依賴模塊之間依賴相同但版本不同的問題,以npm v3-v6的方式去繼續(xù)執(zhí)行安裝操作

  所以其實該命令并沒有真的解決沖突,而是忽略了沖突,以“過時”(v3-v6)的方式進行下載操作

4、--legacy-peer-deps命令作用

  在NPM v7中,現在默認安裝peerDependencies。在很多情況下,這會導致版本沖突,從而中斷安裝過程

  --legacy-peer-deps標志是在v7中引入的,目的是繞過peerDependency自動安裝;它告訴 NPM 忽略項目中引入的各個modules之間的相同modules但不同版本的問題并繼續(xù)安裝,保證各個引入的依賴之間對自身所使用的不同版本modules共存文章來源地址http://www.zghlxwxcb.cn/news/detail-425621.html

到了這里,關于npm install報錯unable to resolve dependency tree的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!

本文來自互聯(lián)網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • npm ERR! code ERESOLVEnpm ERR! ERESOLVE unable to resolve dependency tree

    npm ERR! code ERESOLVEnpm ERR! ERESOLVE unable to resolve dependency tree

    拉取項目到本地 執(zhí)行 npm install 報錯 遇到這個問題首先確認的就是版本是不是太高了,降一下版本。或者通過yarn命令替代npm install命令安裝,同理,啟動也可以采用yarn dev 啟動代替npm run dev 下面教大家用一個NVM工具,這個工具是用來管理node.js版本的 nvm流程安裝 1、卸載node.

    2024年02月13日
    瀏覽(89)
  • 解決npm install時報錯Could not resolve dependency

    最近在新的項目使用npm install時發(fā)現報錯: npm WARN cli npm v9.6.4 does not support Node.js v15.14.0. This version of npm supports the following node versions: `^14.17.0 || ^16.13.0 || =18.0.0`. You can find the latest version at https://nodejs.org/. npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR!? npm ERR! While resolving:

    2024年02月08日
    瀏覽(25)
  • 解決:ERESOLVE unable to resolve dependency tree

    解決:ERESOLVE unable to resolve dependency tree

    NPM版本問題報錯的解決方案 在安裝項目依賴時,很大可能會遇到安裝不成功的問題,其中有一個很大的原因,可能就是因為你的npm版本導致的。 1.npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree 2.ERESOLVE unable to resolve dependency tree 3.如圖: 4.報錯原因 在新版本的npm中,

    2024年02月12日
    瀏覽(99)
  • npm install:Could not resolve dependency:peer... 原因和解決方案

    電腦 npm install 報錯; 報錯日志如下: 上述報錯日志中有個眼: this command with --force, or --legacy-peer-deps 那么npm:何時使用 --force 和 --legacy-peer-deps ? --force 會無視沖突,并強制獲取遠端 npm 庫資源,即使本地有資源也會覆蓋掉 --legacy-peer-deps :安裝時忽略所有 peerDependen

    2024年02月13日
    瀏覽(23)
  • npm install / webdriver-manager update報錯 unable to get local issuer certificate

    我這邊遇到的問題,用的是angular,跑npm install的時候報錯,一開始在.npmrc添加strict-ssl=false但是還是報錯,搜索下記錄。 參考解決: selenium - webdriver-manager update, Error: unable to get local issuer certificate - Stack Overflow 這邊主要問題是跑script? webdriver-manager update --gecko false 的時候報錯,

    2024年02月07日
    瀏覽(21)
  • 安裝 element-ui 的時候出現 ERESOLVE unable to resolve dependency tree

    安裝 element-ui 的時候出現 ERESOLVE unable to resolve dependency tree

    在安裝 element-ui 的時候報錯 unable to resolve dependency tree (無法解決的沖突依賴) 嘗試了以下方法: 1)卸載重裝 node.js (npm 與 node 版本不匹配) 2) 執(zhí)行 npm clean cache --force (清除緩存) 3) 刪除 node_modules 和 package-lock.json;并重新執(zhí)行 npm install 最后依舊解決不了問題,正當我放棄的時

    2024年02月15日
    瀏覽(28)
  • npm install報錯fatal: unable to access ‘https://github.com/nhn/raphael.git/‘: OpenSSL SSL_read 10054

    報錯信息:npm ERR! E:toolsGittGitcmdgit.EXE ls-remote -h -t https://github.com/nhn/raphael.git npm ERR! npm ERR! fatal: unable to access \\\'https://github.com/nhn/raphael.git/\\\': OpenSSL SSL_read: Connection was reset, errno 10054 npm ERR! npm ERR! exited with error code: 128 處理方法 1.git config --global url.\\\"https://\\\" .insteadOf git:// 2.可能是

    2024年02月16日
    瀏覽(32)
  • vue項目啟動npm install和npm run serve時出現錯誤Failed to resolve loader:node-sass

    vue項目啟動npm install和npm run serve時出現錯誤Failed to resolve loader:node-sass

    解決方法: 解決方法: node sass-node loader-sass 14.16.0 4.14.1 8.0.2

    2024年04月26日
    瀏覽(52)
  • 【Synopsys Bug記錄】DC綜合報錯(顯示warning:Unable to resolve reference)

    【Synopsys Bug記錄】DC綜合報錯(顯示warning:Unable to resolve reference)

    ??在綜合一個SOC時,發(fā)現綜合后的門級網表文件缺少了apb系統(tǒng)下的子模塊的網表。該SOC已經成功在FPGA上運行了,按理說在設計上是沒有問題的。在反復查看綜合報告與RTL設計源碼后,終于解決了Bug。 ??查看綜合報告,發(fā)現以下警告和報錯: ??首先分析Warning,這個Wa

    2024年01月20日
    瀏覽(164)
  • IDEA項目啟動報錯:Failed to execute goal on project xxx: Could not resolve dependencies for project

    IDEA項目啟動報錯:Failed to execute goal on project xxx: Could not resolve dependencies for project

    [ERROR] Failed to execute goal on project xxx: Could not resolve dependencies for project Failed to collect dependencies at xxx .xxx-service:jar:dev: Failed to read artifact descriptor for xxxx/maven-snapshots/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of nexus-snaps

    2024年02月03日
    瀏覽(247)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包