【问题标题】:npm install peerDependencies for newer versionnpm install peerDependencies 更新版本
【发布时间】:2018-01-04 14:48:59
【问题描述】:

我是 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 反应 16.0.0 吗?

我想要一个 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"
}

【问题讨论】:

  • 尝试删除node_modules文件夹并再次运行npm i
  • 对不起,我再试一次并点击链接,但它不再起作用。我尝试了 mac 和 windows,但结果相同。

标签: node.js reactjs npm npm-install


【解决方案1】:

来自 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/

【讨论】:

    猜你喜欢
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    • 2016-12-11
    • 1970-01-01
    • 2020-04-06
    • 2018-12-02
    相关资源
    最近更新 更多