簡體   English   中英

新版本的 npm install peerDependencies

[英]npm install peerDependencies for newer version

我是 nodejs 的新手。 我有這樣的 package.json

{
  ...
  "peerDependencies": {
    "react": "16.0.0"
  },

  "dependencies": {
    "some-lib-that-use-old-react": "git+ssh://git@bitbucket.org/xx/somelib.git",
    "other-lib-that-use-old-react": "git+ssh://git@bitbucket.org/xx/other.git"
  },
  ...
}

運行npm install我得到這樣的項目樹

node_modules
|
|__some-lib-that-use-old-react
|__other-lib-that-use-old-react
|__react

我使用 peerDependencies 因為不需要在some libother lib react

(它工作正常,我預期)

但是 react 的版本不是16.0.0 它是來自其他庫的舊版本。

我可以通過 peerDependencies 獲得 react peerDependencies嗎?

我想要一個 lib 位置,我將使用peerDependencies而不是dependencies

我已經嘗試過這樣的npm-shrinkwrap.json

{
  "dependencies": {
    "react": { "version": "16.0.0", "from": "react@16.0.0" }
  }
}

但是它不適用This version of npm is compatible with lockfileVersion@1, but npm-shrinkwrap.json was generated for lockfileVersion@0.

我使用npm 5.5.1 & node 8.9.3 並且在安裝前沒有package-lock.json

謝謝大家來幫忙。

更新 1我將操作系統從 mac 更改為 windows 但它也不起作用。 npm cache clean --force也無濟於事。

更新 2npm i之后 react 的 package.json 看起來像這樣

{
  "_from": "react@old-version",
  "_id": "react@old-version",
  ...
  "_requiredBy": [
    "/some-lib-that-use-old-react",
    "/other-lib-that-use-old-react"
  ],
  ...
  "version": "old-version"
}

來自 NPM 文檔

一條建議:與常規依賴項不同,對等依賴項要求應該是寬松的。 您不應該將您的對等依賴項鎖定到特定的補丁版本。 如果一個 Chai 插件對等依賴於 Chai 1.4.1,而另一個依賴於 Chai 1.5.0,那真的很煩人,僅僅是因為作者很懶,沒有花時間弄清楚他們實際使用的 Chai 的最低版本兼容。

請理解對等依賴項支持最舊版本,因為作者很懶,沒有花時間弄清楚他們兼容的 Chai 的實際最低版本。

查看更多: https : //nodejs.org/en/blog/npm/peer-dependencies/


[2020-10-16更新]

現在是 2020 年。

NPM 7.0.0 版使 peerDependencies 比以前更好,並解決了我的老問題。

請查看以下鏈接以獲取更多信息。

https://github.com/npm/rfcs/blob/latest/implemented/0025-install-peer-deps.md/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM