handle-dependencies-with-yarn-override.mo
Last updated
Last updated
Note: Please create an or even a Pull Request with your feedback, typo correction.
During this standard, we will go through how to handle versions dependencies of different packages to a same package.
If some package doesn't use same versions of a package, depending of the order it will be called, it won't be the same version of package used. We want to ensure that the same version is used everywhere in the app.
Normally this would require to manually edit yarn.lock
file, but it is really bad because this file is deleted each time you install a new package or run a yarn command.
By chance, yarn has a feature override, which allows us to fix those versions dependencies.
Have a react native app installed
Install moment-timezone
(version "0.5.13")
Install react-native-datepicker
(version "1.6.0")
Identify the case:
you just installed a new package (I just installed react-native-datepicker
) and there is a regression in the app (in my case moment.locale()
was not working anymore)
you're trying to set a parameter of a package (e.g. the default locale of moment
) but it's not taken into account by another package
Then open yarn.lock
:
look for your newly installed package
* look for this package dependencies:
try to find other packages which depends on another version of moment
search for moment
in yarn.lock
if another package depends on it but in another version, several lines for moment
will appear:
find which other package it is by searching for moment
in dependencies section of packages:
In package.json
file, add a section 'resolutions' at the same level as the 'dependencies' section.
Specify to which version of moment
depend the two packages, choose same version number for both:
If the package is a dependency of your app, you'll need to set its version in the package.json
:
Run yarn install
.
CHECK 1
Check your yarn.lock file, moment
should appears in only one line:
which means that every package depending on moment
is resolved to a same version (here 2.19.1).
CHECK 2
Your app should works correctly now, regression should be solved. moment
dependencies are solved.
Yarn documentation :