Although relying on resolutions
can be effective, it may not always be the best approach for several reasons:
Here is an alternative method for updating transitive dependencies:
- Delete the entry for the dependency you want to update from
yarn.lock
.
- Run
yarn install
.
This forces yarn to re-resolve the dependency, often resulting in the installation of a newer version of the deleted dependency from yarn.lock
.
For example: Let's say you need to update the vulnerable
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="92fffbfcfbfffbe1e6d2a2bca2bcaa">[email protected]</a>
. In this case, you would remove an entry like this from your
yarn.lock
:
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a5c8cccbccc8ccd6d1e5958b958b9">[email protected]</a>:
version "0.0.8"
resolved "http://10.0.0.1/repository/npm-registry/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=
Then proceed to run yarn install
.
If this approach does not yield results:
Try targeting dependencies higher up in the dependency chain:
- Use
yarn why <dependency>
to identify packages pulling the dependency.
- Delete the parent dependency in
yarn.lock
and run yarn install
.
For example:
Consider a scenario where we update a transitive dependency called minimist
:
$ yarn why minimist
.....
=> Found "mkdirp#<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5b363235323632282f1b6b756b7563">[email protected]</a>"
info This module exists because "eslint#mkdirp" depends on it.
=> Found "optimist#<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e3337303733372d2a1e6e706e706f6e">[email protected]</a>"
info This module exists because "jest#jest-cli#@jest#core#@jest#reporters#istanbul-reports#handlebars#optimist" depends on it.
.....
- Delete all entries related to
minimist
from yarn.lock and execute yarn install
- when this doesn't yield the desired outcome due to dependencies requiring specific versions such as <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0ada9aea9ada9b3b480f0eef0eef8">[email protected]</a>
and <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94f9fdfafdf9fde7e0d4a4baa4baa5a4">[email protected]</a>
- Delete immediate parents of
minimist
from yarn.lock: mkdirp
and optimist
.
- Run
yarn install
.
Rerun yarn why minimist
:
$ yarn why minimist
.....
=> Found "mkdirp#<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a5c8cccbccc8ccd6d1e5948b978b90">[email protected]</a>"
info This module exists because "eslint#mkdirp" depends on it.
=> Found "optimist#<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4f2226212622263c3b0f7f617f617e7f">[email protected]</a>"
info This module exists because "jest#jest-cli#@jest#core#@jest#reporters#isanbul-reports#handlebars#more_on_optimist" depends on it.
.....
Observing that
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f79a9e999e9a9e8483b7c7d9c7d9cf">[email protected]</a>
has been updated to <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2f4246414642465c5b6f1e011d011a">[email protected]</a>
, while <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8fe2e6e1e6e2e6fcfbcfbfa1bfa1bebf">[email protected]</a>
remains.
Delete the next dependency in the chain from yarn.lock
: handlebars
- Proceed with
yarn install
.
- Rerun
yarn why minimist
- status quo remains, <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a1ccc8cfc8ccc8d2d5e1918f918f9091">[email protected]</a>
persists.
- Delete the following dependency in the chain from
yarn.lock
: istanbul-reports
- Execute
yarn install
.
- Rerun
yarn why minimist
: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="adc0c4c3c4c0c4ded9ed9d839d839c9d">[email protected]</a>
has disappeared now after updating istanbul-reports
.