I have angular
in my dependencies at 1.5.11:
{
"dependencies": {
"angular": "1.5.11",
"angular-foundation": "0.7.0"
}
}
angular-foundation
happens to depend on angular@>=1.3.0
.
Why does Yarn install [email protected]
as a nested dependency of angular-foundation instead of using the project's version? This causes angular to exist twice in the app and doesn't work properly:
node_modules
angular (1.5.11)
angular-foundation (0.7.0)
node_modules
angular (1.6.9)
This doesn't happen with [email protected] - npm uses 1.5.11 for both the app and the package.
With npm or yarn, you can install a package under a custom alias. This enables you to install multiple versions of a package in the same project.
When we install a package using the npm install package-name command, it will download the current stable version of the package inside node_modules folder and add it to package. json file. To install multiple versions of the same package, we need to use the package alias syntax which is supported from the npm v6. 9.0.
The good news is that you can have it done directly via NPM! What can be done in this case is an idea called "package alias". So you can have multiple versions of the same package running in your app and you can work on the upgrades mitigating possible issues.
Using npm install npm install all the packages in the package. json . But it looks like you need to specify each package when using yarn add according to https://yarnpkg.com/en/docs/cli/add. yarn add package-name installs the “latest” version of the package.
You need to use Yarn
resolutions for this
https://yarnpkg.com/lang/en/docs/selective-version-resolutions/
So your package.json
will become like this
{
"name": "depdencies",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"angular": "1.5.11",
"angular-foundation": "0.7.0"
},
"resolutions": {
"**/angular": "1.5.11"
}
}
Which tells yarn
that any child angular dependency will be set to 1.5.11
. After updating this run below
$ rm yarn.lock
$ yarn
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