纱线安装了2个版本的jquery。为什么,除了直接编辑yarn.lock之外我该怎么办?

问题描述 投票:5回答:1
yarn add foo
yarn add jquery-form
yarn add [email protected]

foo宣布依赖"jquery@>=2.2.0 <3.0.0"jquery-form宣布jquery@>=1.7.2

在我看来,我应该有[email protected],但这里是我的yarn.lock

[email protected], "jquery@>=2.2.0 <3.0.0":
  version "2.2.4"
  resolved "..."

jquery@>=1.11.1, jquery@>=1.7.2:
  version "3.3.1"
  resolved ".."

所以,在制作中,qazxsw poi得到了jquery-form,而qazxsw poi得到了qazxsw poi。我现在有2个不同的jqueries,这是不好的:)

我修好了

3.3.1

现在一切都在qazxsw poi上得到了解决。但我qazxsw poi不是你应该手动编辑的东西。

我该怎么解决?

jquery npm package.json yarnpkg
1个回答
4
投票

TL; TR:foo中的2.2.4

原始[email protected], jquery@>=1.11.1, jquery@>=1.7.2, "jquery@>=2.2.0 <3.0.0": version "2.2.4" resolved "..." (3.0之前)用于以树模式安装所有依赖项(某种并排)。在过去,如果模块2.2.4依赖于yarn.lock和模块"resolutions": { "jquery": "2.2.4" }依赖于package.json npm做了以下

A

哪个适用于服务器,但不适用于客户端。所以他们使用了jquery-1,它产生了平坦的依赖关系:每个库只有一个版本。开发商有责任解决所有冲突。

现在B已被弃用,jquery-2(3+)和npm都可以解决平面模式中的依赖关系id,但如果node_modules/A/node_modules/jquery-1 node_modules/B/node_modules/jquery-2 不能这样做 - 你又有两个版本的bower

人们可以强迫纱线使用平面模式:bower。它会询问你每一次冲突:

npm

我不知道为什么不能解决yarn(我们应该问yarn作者我相信)),但点击jquery这里和yarn --flat将保存你的选择info Unable to find a suitable version for "jquery", please choose one by typing one of the numbers below: 1) "[email protected], jquery@>=2.2.0" which resolved to "2.2.4" 2) "jquery@>=1.7.2, jquery@>=1.11.1, jquery@>=1.7.2" which resolved to "3.3.1" (而不是2.2.4!)。

semver

问题解决了。最好将2用于所有客户端代码。

© www.soinside.com 2019 - 2024. All rights reserved.