yarn add foo
yarn add jquery-form
yarn add [email protected]
foo declares dependency "jquery@>=2.2.0 <3.0.0", jquery-form declares jquery@>=1.7.2
In my opinion I should have [email protected], but here is my 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 ".."
So, in productuion jquery-form got 3.3.1 while foo got 2.2.4.
I now have 2 different jqueries which is not good:)
I fixed it with
[email protected], jquery@>=1.11.1, jquery@>=1.7.2, "jquery@>=2.2.0 <3.0.0":
version "2.2.4"
resolved "..."
Everything is resloved on 2.2.4 now. But I yarn.lock is not something you should edit manually.
How should I solve it?
In order to update your version of Yarn, you can run one of the following commands: npm install --global yarn - if you've installed Yarn via npm (recommended) curl --compressed -o- -L https://yarnpkg.com/install.sh | bash if you're on Unix. otherwise, check the docs of the installer you've used to install Yarn.
lock file is generated automatically. Also any time a dependency is added, removed, or modified with the yarn CLI (e.g. running the yarn install command), the yarn. lock file will update automatically.
Installing Options Installing all dependencies: yarn or yarn install. Installing one and only one version of a package: yarn install --flat. Forcing a re-download of all packages: yarn install --force. Installing only production dependencies: yarn install --production.
yarn remove <package...> Running yarn remove foo will remove the package named foo from your direct dependencies updating your package. json and yarn. lock files in the process. Other developers working on the project can run yarn install to sync their own node_modules directories with the updated set of dependencies.
TL;TR: "resolutions": { "jquery": "2.2.4" } in package.json
Original npm (before 3.0) used to install all dependencies in tree mode (some kind of side-by-side). In old times if module A depended on jquery-1 and module B depended on jquery-2 npm did the following
node_modules/A/node_modules/jquery-1
node_modules/B/node_modules/jquery-2
Which is OK for server, but not for client. So they used bower which produced flat dependencies: only one version for each library. Its was developer's duty to resolve all conflicts.
Nowadays bower is deprecated and both npm (3+) and yarn resolve dependencies in flat mode id they can, but if yarn can't do that -- you have two versions of jquery again.
One can force yarn to use flat mode: yarn --flat. It will ask you about every single conflict:
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"
I do not know why can't it be resolved to 2.2.4 (we should ask semver author I believe)), but click 2 here and yarn will save your choice to package.json (not yarn.lock!).
"author": "Foo",
"license": "UNLICENSED",
"resolutions": {
"jquery": "2.2.4"
}
Problem is solved. It is good to use yarn --flat for all client-side code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With